HDU1788 Chinese remainder theorem again【中国剩余定理】
来源:互联网 发布:淘宝大麻种子 编辑:程序博客网 时间:2024/05/23 02:03
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1788
题目大意:
题目前边的描述是多余的。。。一个正整N除以M1余M1-a,除以M2余M2-a,除以M3余M3-a,
即除以Mi余Mi-a(a < Mi < 100),求满足条件的最小的数。
思路:
这是一道中国剩余定理的基础题。由题目得出N % Mi + a = Mi,即得:N + a = 0(mod Mi)。也
就是所有的Mi都能整除N+a。那么题目就变为了求N个Mi的最小公倍数,最后再减去a。
AC代码:
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#define LL __int64using namespace std;LL GCD(LL a,LL b){ if(b == 0) return a; return GCD(b,a%b);}int main(){ int N,K,m; while(cin >> N >> K && (N||K)) { LL ans = 1; for(int i = 0; i < N; ++i) { cin >> m; ans = (ans*m)/GCD(ans,m); } cout << ans - K << endl; } return 0;}
0 0
- 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 中国剩余定理
- Chinese remainder theorem again(中国剩余定理+不互质版+hud1788)
- HDU1788 Chinese remainder theorem again
- hdu1788 Chinese remainder theorem again
- HDU1788-Chinese remainder theorem again
- 中国剩余定理 Chinese remainder theorem(CRT)
- HDU1788 Chinese remainder theorem again 最小公倍数
- hdu1788 Chinese remainder theorem again 最小公倍数
- hdu 1788 Chinese remainder theorem again 披着中国剩余定理的皮
- hdu 1788Chinese remainder theorem again(中国剩余定理or同余性质的应用)
- 中国剩余定理(chinese remainder theorem)【模板】
- 中国剩余定理(chinese remainder theorem)【模板】
- HDU1788Chinese remainder theorem again(中国剩余定理 简单)
- Chinese remainder theorem again + 数论
- Ubuntu中安装使用libxml2
- Android OTA升级原理和流程分析(四)---Android系统Recovery模式的工作原理
- android学习之创建自定义控件(续)
- IEEE深度对话Facebook人工智能负责人Yann LeCun:让深度学习摆脱束缚
- Python内置的字符串处理函数整理
- HDU1788 Chinese remainder theorem again【中国剩余定理】
- 访问者
- 阿里巴巴2015实习面试
- Android异步加载全解析之使用AsyncTask
- Android FoldingLayout 折叠布局 原理及实现(一)
- Linux 磁盘配额控制 quota
- CSDN优秀博客连接,博客之星连接。
- Find Peak Element
- 通知中心