一些关于中国剩余定理的数论题(POJ 2891/HDU 3579/HDU 1573/HDU 1930)
2013-07-30 03:01
671 查看
2891 -- Strange Way to Express Integers
View Code
——written by Lyon
#include <cstdio> #include <iostream> #include <cmath> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a;} inline LL lcm(LL a, LL b) { return a / gcd(a, b) * b;} void gcd(LL a, LL b, LL &d, LL &x, LL &y) { if (b) { gcd(b, a % b, d, y, x); y -= a / b * x;} else d = a, x = 1, y = 0; } LL A[6], R[6]; bool check(LL a) { for (int i = 0; i < 3; i++) { if (a % 100 > 27 || a % 100 <= 0) return false; a /= 100; } return true; } LL cal() { LL d, x, y, a = A[0], r = R[0]; for (int i = 1; i < 4; i++) { LL dr = R[i] - r; gcd(a, A[i], d, x, y); if (dr % d) { puts("WTF??"); while (1) ; } LL tmp = a * x; //a = lcm(a, A[i]); a *= A[i]; tmp %= a; tmp *= dr / d; tmp += r; r = (tmp % a + a) % a; //cout << a << '~' << r << endl; } while (!check(r)) r += a; //cout << r << ' ' << a << endl; return r; } LL cal(LL x) { for (int i = 0; i < 4; i++) R[i] = x % 100, x /= 100; //for (int i = 0; i < 4; i++) cout << A[i] << ' ' << R[i] << endl; return cal(); } const LL ep[3] = { 10000, 100, 1}; char out[111111]; int main() { //freopen("in", "r", stdin); int T, n, p; LL tmp, x; cin >> T; while (T-- && cin >> n) { p = 0; for (int i = 0; i < 4; i++) cin >> A[i]; reverse(A, A + 4); for (int i = 0; i < n; i++) { cin >> tmp; tmp = cal(tmp); for (int i = 0; i < 3; i++) { x = tmp / ep[i] % 100; out[p++] = x == 27 ? ' ' : (x - 1 + 'A'); } } out[p] = 0; while (p > 0 && out[p - 1] == ' ') out[--p] = 0; puts(out); } return 0; }
View Code
——written by Lyon
相关文章推荐
- 中国剩余定理小结 (互质,非互质) (poj 1006,hdu 3579)
- HDU 3579-数论训练A题 exgcd加中国剩余定理
- hdu 3579 Hello Kiki 不互质的中国剩余定理
- POJ 2891 Strange Way to Express Integers 中国剩余定理
- hdu 3579(中国剩余定理+考虑0)
- poj 2891 Strange Way to Express Integers 模数不互素的中国剩余定理
- hdu - 3579 - Hello Kiki - (不互质的中国剩余定理)
- poj 2891 Strange Way to Express Integers (非互质的中国剩余定理)
- Poj 2891 中国剩余定理 非互素
- HDU 3579 Hello Kiki 中国剩余定理(合并方程
- POJ_2891_中国剩余定理
- poj 2891 Strange Way to Express Integers——使用中国剩余定理中处理某些方程模数不互质的方法
- POJ 1006 中国剩余定理(孙子定理) ——数论
- HDU --- 5446 Unknown Treasure 数论综合【Lucas定理 + 中国剩余定理 + 快速乘 + 思维】
- lightoj 1319 - Monkey Tradition 中国剩余定理(孙子定理)+poj 2891 Strange Way to Express Integers
- POJ 2891 Strange Way to Express Integers 中国剩余定理的一般情况
- POJ_2891_Strange Way to Express Integers(非互质的中国剩余定理)
- poj 2891《中国剩余定理》
- POJ 2891 Strange Way to Express Integers 中国剩余定理MOD不互质数字方法
- HDU 3579 Hello Kiki 中国剩余定理 不互质情况