hdu1788 Chinese remainder theorem again
来源:互联网 发布:手机淘宝免费开店流程 编辑:程序博客网 时间:2024/06/04 19:13
求最小公倍数;Lcm 的数据类型是LL, 忽略了,WA了一次!
本题要求的是N%Mi = Mi - a; 即:N%Mi + a = Mi;则有:N + a ≡ 0 ( mod Mi);
定理:若有:a ≡ b(mod mi),当且仅当:a ≡ b (mod [m1 * m2 * ···········mn]);
#include <iostream>#include <cstdio>using namespace std;typedef long long LL;LL Gcd(LL a, LL b){ return b == 0 ? a : Gcd(b, a%b);}int main(){ int k, a; while(cin>>k>>a) { LL Lcm = 1; if(k == 0 && a == 0) break; int b; for(int i = 0; i < k; ++i) { cin>>b; Lcm = (b * Lcm) / Gcd(Lcm, b); } cout<<Lcm - a<<endl; } return 0;}
0 0
- HDU1788 Chinese remainder theorem again
- hdu1788 Chinese remainder theorem again
- HDU1788-Chinese remainder theorem again
- HDU1788 Chinese remainder theorem again 最小公倍数
- hdu1788 Chinese remainder theorem again 最小公倍数
- Chinese remainder theorem again(hdu1788中国剩余定理)
- HDU1788 Chinese remainder theorem again 中国剩余定理
- HDU1788 Chinese remainder theorem again【中国剩余定理】
- 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
- Chinese remainder theorem again(HDU 1788)
- hdu 1788 Chinese remainder theorem again 最小公倍数
- 2013秋13级预备队集训练习4 --C - The Land of Justice
- 10个迷惑新手的Cocoa,Objective-c开发难点和问题
- android 手电筒开发
- 数据结构开发日志
- windows下qt creator中加入qwt插件
- hdu1788 Chinese remainder theorem again
- kafka安装
- Spring学习(0)——Spring架构师对Spring的介绍
- 2013秋13级预备队集训练习4 --D - How Many Points of Intersection?
- CentOS下每天自动备份mysql数据库
- sicily 1500.Prime Gap
- Linux设备驱动程序(LDD3)中snull的编译问题
- python小结
- java_web用户的自动登录模块的实现