【NOIP2012】同余方程
2016-11-15 17:25
204 查看
【codevs 1200】
1200 同余方程 2012年NOIP全国联赛提高组
时间限制: 1 s
空间限制: 128000 KB
题目等级 : 钻石 Diamond
题解
题目描述 Description
求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解。
输入描述 Input Description
输入只有一行,包含两个正整数 a, b,用 一个 空格隔开。
输出描述 Output Description
输出只有一行包含一个正整数x0,即最小正整数解,输入数据保证一定有解。
样例输入 Sample Input
3 10
样例输出 Sample Output
7
数据范围及提示 Data Size & Hint
【数据范围】
对于 40% 的数据, 2 ≤b≤ 1,000 ;
对于 60% 的数据, 2 ≤b≤ 50,000,000
对于 100% 的数据, 2 ≤a, b≤ 2,000,000,000
1200 同余方程 2012年NOIP全国联赛提高组
时间限制: 1 s
空间限制: 128000 KB
题目等级 : 钻石 Diamond
题解
题目描述 Description
求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解。
输入描述 Input Description
输入只有一行,包含两个正整数 a, b,用 一个 空格隔开。
输出描述 Output Description
输出只有一行包含一个正整数x0,即最小正整数解,输入数据保证一定有解。
样例输入 Sample Input
3 10
样例输出 Sample Output
7
数据范围及提示 Data Size & Hint
【数据范围】
对于 40% 的数据, 2 ≤b≤ 1,000 ;
对于 60% 的数据, 2 ≤b≤ 50,000,000
对于 100% 的数据, 2 ≤a, b≤ 2,000,000,000
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int ans = 0; int a,b,x,y,s; void cal(int a,int b) { if(b == 0) x = 1,y = 0,ans = a; else { cal(b,a % b); s = x,x = y,y = s - a / b * y; return; } } int main() { scanf("%d %d",&a,&b); cal(a,b); while(x < 0) x += b; printf("%d\n",x / ans); return 0; }
相关文章推荐
- noip2012 同余方程 关于gcd及exgcd
- COGS——T 1265. [NOIP2012] 同余方程
- 洛谷 P1082 [NOIP2012 D2T1] 同余方程
- 【扩展欧几里得】Codevs 1200: [noip2012]同余方程
- [NOIP 2012]同余方程 扩展欧几里得
- 扩展欧几里得模板(洛谷1082 同余方程NOIP 2012 提高组 第二天 第一题)
- 【NOIP2012提高组】同余方程 (扩展欧几里得算法)
- noip2012 同余方程 exgcd
- noip2012 同余方程
- 扩展欧几里德 noip 2012 day2 同余方程
- [NOIP2012] 同余方程|扩展欧几里得算法
- 【codevs1200】 NOIP2012—同余方程
- 【codevs1200】 NOIP2012—同余方程
- 【NOIP2012】洛谷1082 同余方程 扩展欧几里得详解
- 【codevs 1200】【NOIP 2012】同余方程 拓展欧几里德求乘法逆元模板题
- [NOIP 2012] 同余方程 · 拓展欧几里得
- Noip 2012 同余方程
- CJOJ 1029 【NOIP2012】同余方程
- NOIP 2012 同余方程 (COGS 1265) 求逆元 扩展欧几里得算法
- 【NOIP2012】洛谷1082 同余方程