Hdu 1788 Chinese remainder theorem again
来源:互联网 发布:橙光立绘制作软件 编辑:程序博客网 时间:2024/06/05 11:45
大意不再赘述。
思路:其实是最小公倍数。
N+a ≡ 0 (mod Mi),求得lcm之后减去a即可。
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;typedef __int64 LL; //long long WAconst int MAXN = 110;int n;LL lcm, a;LL gcd(LL a, LL b){return b == 0 ? a:gcd(b, a%b);}int read_case(){scanf("%d%I64d", &n, &a);if(!n && !a) return 0;lcm = 1;for(int i = 1; i <= n; i++){LL m;scanf("%I64d", &m);lcm = lcm / gcd(lcm, m) * m;}return 1;}void solve(){LL ans = lcm-a;printf("%I64d\n", ans);}int main(){while(read_case()){solve();}return 0;}
- hdu 1788 Chinese remainder theorem again
- Hdu 1788 Chinese remainder theorem again
- HDU 1788 Chinese remainder theorem again 数论
- hdu 1788 Chinese remainder theorem again
- HDU 1788 Chinese remainder theorem again
- hdu 1788 Chinese remainder theorem again(最小公倍数)
- Chinese remainder theorem again(HDU 1788)
- hdu 1788 Chinese remainder theorem again 最小公倍数
- hdu 1788 Chinese remainder theorem again
- 【HDU】 1788 Chinese remainder theorem again
- HDU 1788 Chinese remainder theorem again
- hdu 1788 Chinese remainder theorem again 多个数的最小公倍数
- HDU 1788 Chinese remainder theorem again 中国剩余定理转换
- HDU 1788 Chinese remainder theorem again 中国剩余定理
- HDU 1788——Chinese remainder theorem again
- hdu 1788 Chinese remainder theorem again((数学:简单题)
- 【数论】 HDOJ 1788 Chinese remainder theorem again
- HDOJ-1788 Chinese remainder theorem again(数论)
- 微信摇一摇功能代码解析
- 课后总结:1.1_编程及java基础常识
- 文件系统:FAT(FAT16),FAT32,VFAT,NTFS
- 关于ARM的22个常用概念--的确经典
- php无法获得远程文件大小
- Hdu 1788 Chinese remainder theorem again
- 课后总结:1.2_标识符
- 怎么获得当前LCU的above和left LCU的分割深度信息?(已更新)
- 一个二三线互联网公司,拿什么追赶百度腾讯?
- 关于打包C++项目
- Java 版本 特征 和 历史
- linux下的ssh命令
- Android APN的设置问题
- ARM启动代码学习(一)RO和RW还有ZI代表什么?(转载)