Mdular Linear Equatin 模线性方程(同余方程)
来源:互联网 发布:游戏程序员招聘 编辑:程序博客网 时间:2024/05/24 07:27
//如果GCD(a,b)不能整除c,则ax + by = c 没有整数解//ax≡b(mod n) (n>0)//上式等价于二元一次方程ax - ny = bvoid modular_linear_equation(int a, int b, int n){int d, x, y, x0, gcd;//可以减少扩展欧几里得溢出的可能gcd = GCD(a, n);if (b%gcd != 0) {cout << "no solution" << endl;return;}a /= gcd;b /= gcd;n /= gcd;d = extended_euclid(a, n, x, y);if (b%d == 0) {x0 = (x*(b / d)) % n;//x0:basic solutionint ans = n;//min x = (x0%(n/d)+(n/d))%(n/d)for (int i = 0; i < d; i++) {ans = (x0 + i*(n / d)) % n;cout << ans << endl;}}else cout << "no solution" << endl;}
阅读全文
0 0
- Mdular Linear Equatin 模线性方程(同余方程)
- 同余问题之模方程模板
- 孙子定理,模线性同余方程
- 线性同余方程
- 解同余方程
- 线性同余方程
- 线性同余方程
- 线性同余方程
- 一次同余方程
- poj2115 同余方程
- 同余方程
- NOIP2012 同余方程
- 【noip2012】同余方程
- BZOJ2995同余方程
- NOIP2012 同余方程
- NOIP2012D2T1 同余方程
- hdu1573 同余方程
- noip2012同余方程
- 添加phpiredis扩展的时候报错
- APK Signature
- 深入浅出讲解:php的socket通信
- 优先队列的基础知识
- C++中的static关键字详解
- Mdular Linear Equatin 模线性方程(同余方程)
- PHP导出word,CVS,PDF
- Python没有运行快捷按钮
- Android DecorView浅析
- android 系统数据业务---打开
- mysql的两种安装方式
- Android APK 上架
- next-permutation
- python常用模块与socket编程