HDU1788 Chinese remainder theorem again 最小公倍数
来源:互联网 发布:淘宝流量和访客怎么刷 编辑:程序博客网 时间:2024/05/22 07:06
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1788
分析:由n%m=m-a,==>n%m+a=m,即,n+a≡0(mod m),其实(n+a)就是m的倍数,那么问题就变为了找出∑mi的最小公倍数,再减去a了。
实现代码如下:
#include <iostream>#include <cstdio>using namespace std;typedef long long LL;LL gcd(LL a,LL b){ return !b?a:gcd(b,a%b);}int main(){ int n,k,t; while(cin>>n>>k) { if(n==0&&k==0) break; LL ans=1; for(int i=0;i<n;i++) { cin>>t; ans=t/gcd(ans,t)*ans; } cout<<ans-k<<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【中国剩余定理】
- hdu 1788 Chinese remainder theorem again(最小公倍数)
- hdu 1788 Chinese remainder theorem again 最小公倍数
- hdu 1788 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
- 【数论】 HDOJ 1788 Chinese remainder theorem again
- 【leetcode】【单链表】【109】Convert Sorted List to Binary Search Tree
- STM32M4 内部flash编程
- 20150527常量变量_练习_运算符表达式练习
- memcache的配置
- 第7条:避免使用终极方法
- HDU1788 Chinese remainder theorem again 最小公倍数
- 二叉树的遍历
- 异常
- leetcode[141&142]:Linked List Cycle I & II
- linux 平台性能分析工具
- POJ 1006
- IOS打包.a静态库 .a内外控制器UIViewController跳转
- 20150528分支结构
- 应用程序使用同一个TAG的Log方法