ACMSTEP 2.1.5 又见GCD //数论 GCD
2011-08-10 12:23
344 查看
原题地址
第一个想法是:枚举法暴力求解 我原以为会超时。。。没想到A了。。
这题太坑爹了
第一个想法是:枚举法暴力求解 我原以为会超时。。。没想到A了。。
这题太坑爹了
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <vector> #include <queue> #include <algorithm> int gcd(int x, int y) { if (!x || !y) return x > y? x:y; for (int t; t = x %y; x =y ,y =t); return y ; } using namespace std; int main() { int cases , a, b, i; cin>>cases; while (cases--) { cin>>a>>b; for (i=b+1; i<=1000000; i++) { if (gcd(a , i) == b) break; } cout<<i<<endl; } return 0; }
相关文章推荐
- 【数论】二进制GCD
- 新视野OJ 2190 [SDOI2008]仪仗队 (数论-gcd)
- 数论学习小记 其之三 Gcd与Lcm
- hdu4497——GCD and LCM(数论&容斥原理or排列组合)
- HDU 1695 GCD (数论-整数和素数,组合数学-容斥原理)
- 【bzoj2820】YY的GCD 线性筛法+莫比乌斯反演+数论分块
- ACMSTEP 2.1.4 Largest prime factor //数论 素数
- POJ 2429 - GCD & LCM Inverse(数论)
- HDU 5869 Different GCD Subarray Query(数论+BIT)
- 数论继续学习3--最大公约数gcd和最小公倍数lcm
- HDU4497:GCD and LCM(数论)
- UVA 11388 - GCD LCM(数论)
- Codeforces-798C-Mike and gcd problem(贪心+数论)
- BZOJ_P2820 YY的GCD(数论+莫比乌斯反演)
- HDU 1695 GCD (数论-整数和素数,欧拉函数,组合数学-容斥原理)
- POJ1061 数论gcd
- HDU5514 Frogs(GCD+欧拉函数+数论)
- ACMSTEP 2.1.6 招新朋友 //数论 互质
- Uva 11426 GCD - Extreme (II)(基本数论)
- 数论——斐波那契练习题一——斐波那契中的gcd