链接:https://ac.nowcoder.com/acm/contest/890/D
来源:牛客网

题目描述

His majesty chatted with Han Xin about the capabilities of the generals. Each had their shortcomings. His majesty asked, “How many troops could I lead?" Han Xin replied, Your highness should not lead more than 100000." His majesty said, ``And what about you? `For your humble servant, the more the merrier!" said Han Xin.

—Records of the Grand Historian

Han Xin was a military general who served Liu Bang during the Chu-Han contention and contributed greatly to the founding of the Han dynasty. Your friend, in a strange coincidence, also named Han Xin, is a military general as well.

One day you asked him how many troops he led. He was reluctant to tell you the exact number, but he told you some clues in certain form, for example:

  • if we count the troops by threes, we have two left over;
  • if we count by fives, we have three left over;
  • if we count by sevens, two are left over;

  • You wonder the number of his troops, or he was simply lying. More specifically, you would like to know the minimum possible number of troops he leads, and if the minimum number is too large, then you suspect he was lying.

输入描述:

The first line of input contains two integers n, m (1≤n≤100,1≤m≤1018)(1 \leq n \leq 100, 1 \leq m \leq 10^{18})(1≤n≤100,1≤m≤1018), the number of clues he told you and the threshold that you think he was probably lying.

The remaining part of the input are n lines, specifying the clues, Each line consists of two integers a, b (0≤b<a<105)(0 \leq b < a < 10^5)(0≤b<a<105), representing a clue that b troops are left over if we count them by a’s.

输出描述:

If there does not exist a non-negative number of troops satisfying all clues, print he was definitely lying\texttt{he was definitely lying}he was definitely lying; otherwise, if the minimum non-negative possible number of troops is greater than m, print he was probably lying\texttt{he was probably lying}he was probably lying; otherwise, print the minimum non-negative number.

示例1
输入

3 100
3 2
5 3
7 2

输出

23

示例2
输入

4 10000
12 7
15 2
30 5
8 6

输出

he was definitely lying

示例3
输入

2 10
11 3
19 7

输出

he was probably lying

思路:看起来像是excrt的模板题,但是它的范围很大,会爆long long,所以使用__int128,,,一个很玄学的东西,我fo了。

#include<bits/stdc++.h>
using namespace std;
#define ll __int128
ll n,m,a1,a2,m1,m2;
ll exgcd(ll a,ll b,ll &x,ll &y)
{if(!b){x=1;y=0;return a;}ll d=exgcd(b,a%b,y,x);y-=a/b*x;return d;
}
void print(__int128 x){if(x<0){putchar('-');x=-x;}if(x>9)print(x/10);putchar(x%10+'0');
}
int main()
{scanf("%lld%lld",&n,&m);scanf("%lld%lld",&a1,&m1);int flag=1;for(ll i=0;i<n-1;i++){scanf("%lld%lld",&a2,&m2);ll k1,k2,d,t;d=exgcd(a1,a2,k1,k2);if((m2-m1)%d){flag=0;break;}k1*=(m2-m1)/d;t=a2/d;k1=(k1%t+t)%t;m1=a1*k1+m1;a1=a1/d*a2;if(a1<0)a1=-a1;}ll ans=(m1%a1+a1)%a1;if(!flag)puts("he was definitely lying");else if(ans>m)puts("he was probably lying");else print(ans);
}

牛客多校第十场 Han Xin and His Troops(扩展中国剩余)相关推荐

  1. 牛客多校第十场F-Popping Balloons

    题目连接 牛客多校F-PoppingBalloons 题意: 用枪打气球,可以横着打三次,竖着打三次,横着打可以把那一行的气球全打下来,竖着打可以把那一列的气球全打下来,但是,每两次相邻的横着打或者竖 ...

  2. 【牛客多校第十场】Coffee Chicken

    题目描述 Dr. JYY has just created the Coffee Chicken strings, denoted as S(n). They are quite similar to ...

  3. 2019牛客多校第十场 F.Popping Balloons

    使用线段树,将(1,1+r,1+2r),(2,2+r,2+2r),(3,3+r,3+2r)以此类推,每个看成一个节点,对y进行建树,然后枚举x,维护最大值即可. 代码如下: #include<c ...

  4. 24dian(牛客多校第三场)

    24dian(牛客多校第三场) 题意: 给你n张牌,每张牌的大小为1 ~ 13,问这些牌与加减乘除任意组合(可以使用括号),且但所有的有效解在计算过程中都涉及到分数,即非整数,能否组成答案m,如果可以 ...

  5. 2019牛客多校第四场 I题 后缀自动机_后缀数组_求两个串de公共子串的种类数

    目录 求若干个串的公共子串个数相关变形题 对一个串建后缀自动机,另一个串在上面跑同时计数 广义后缀自动机 后缀数组 其他:POJ 3415 求两个串长度至少为k的公共子串数量 @(牛客多校第四场 I题 ...

  6. 2022牛客多校(十)

    2022牛客多校(十) 一.比赛小结 比赛链接:"蔚来杯"2022牛客暑期多校训练营10 二.题目分析及解法(基础题) F.Shannon Switching Game? 题目链接 ...

  7. 牛客多校第四场【B-Basic Gcd Problem】

    牛客多校第四场[B-Basic Gcd Problem] 题目链接:https://ac.nowcoder.com/acm/contest/5669/B 思路:先要理解公式,多看几个数据基本就会有点想 ...

  8. 牛客多校第三场 B【Classical String Problem】

    牛客多校第三场 B[Classical String Problem] 链接:https://ac.nowcoder.com/acm/contest/5668/B 来源:牛客网 题目描述 Given ...

  9. 2019年牛客多校第1场 赛后总结

    A题 :Equivalent Prefixes  题意:就是给你两个有n个不同数的串,然后保证1-p区间内任选一个区间,使得区间中最小值的下标相同,找到最大的p值  思路:我的思路是设置两个单调栈,然 ...

最新文章

  1. Apache软件历史版本下载地址
  2. couchdb 任意命令执行漏洞 cve-2017-12636
  3. 一些今天看到的好句子
  4. linux kernel 中mdelay() 与msleep()的区别
  5. Spring Bean 定义
  6. final 最终 java 1614876717
  7. 安卓案例:利用帧动画动态显示时间
  8. 云计算OpenStack:云在身边博客园
  9. 【Java】Java-XML解析利器-SAX-高性能-易用
  10. AlloyTeam|腾讯全端 AlloyTeam 团队 - HTML5开源图像处理框架AlloyImage
  11. 牛x!一个比传统数据库快 100-1000 倍的数据库!
  12. 一款开源的中国象棋人工智能程序
  13. 教务管理系统数据字典mysql_数据库课程设计报告--教务管理系统设计
  14. maven的详细下载和安装
  15. 谷歌logo的“前世今生”
  16. 企业内部即时通讯工具WorkPlus,支持内网私有化部署
  17. 笔记本BIOS能检测到固态,进入系统后磁盘管理不显示固态硬盘
  18. CERC2017 F-Faulty Factorial【数论】
  19. 海思开发板遇到的问题启发性的链接
  20. rand和srand的用法

热门文章

  1. iOS 史上最全App上架流程分享
  2. Arduino + SmartAirFilter 制作智能感应的 PM 空气净化器
  3. 3dmax如何呈现Z频道
  4. html 文件常用格式
  5. 如何测试一个一次性水杯
  6. 怎么打造属于自己的天猫精灵
  7. eclips 安装问题
  8. 【Python】原来处理大文件也可以这么简单?
  9. vue element ui 利用xslx导出文档表格功能(纯前端导出下载文档)
  10. G1D38-Evaluation Metrics