HDU 4569 (推导)
来源:互联网 发布:linux http管理 编辑:程序博客网 时间:2024/06/06 18:24
Special equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 435 Accepted Submission(s): 274
Special Judge
Problem Description
Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known integers. We call f(x) 0 (mod m) congruence equation. If m is a composite, we can factor m into powers of primes and solve every such single equation after which we merge them using the Chinese Reminder Theorem. In this problem, you are asked to solve a much simpler version of such equations, with m to be prime's square.
Input
The first line is the number of equations T, T<=50.
Then comes T lines, each line starts with an integer deg (1<=deg<=4), meaning that f(x)'s degree is deg. Then follows deg integers, representing an to a0 (0 < abs(an) <= 100; abs(ai) <= 10000 when deg >= 3, otherwise abs(ai) <= 100000000, i<n). The last integer is prime pri (pri<=10000).
Remember, your task is to solve f(x) 0 (mod pri*pri)
Then comes T lines, each line starts with an integer deg (1<=deg<=4), meaning that f(x)'s degree is deg. Then follows deg integers, representing an to a0 (0 < abs(an) <= 100; abs(ai) <= 10000 when deg >= 3, otherwise abs(ai) <= 100000000, i<n). The last integer is prime pri (pri<=10000).
Remember, your task is to solve f(x) 0 (mod pri*pri)
Output
For each equation f(x) 0 (mod pri*pri), first output the case number, then output anyone of x if there are many x fitting the equation, else output "No solution!"
Sample Input
42 1 1 -5 71 5 -2995 99292 1 -96255532 8930 98114 14 5458 7754 4946 -2210 9601
Sample Output
Case #1: No solution!Case #2: 599Case #3: 96255626Case #4: No solution!
题意:求一个方程模m^2为0是否有解。
因为m是素数,所以方程模m^2为0必然需要方程模m为0,而所有的x(x>=m)模m为0,必
然有(x-m)模m为0.
所以就可以寻找[0,m-1]中f(x)模m为0的x,然后判断x+m,x+2m....是不是满足。
#include <iostream>#include <algorithm>#include <string.h>#include <stdio.h>#include <map>#include <vector>#include <math.h>#include <queue>using namespace std;#define maxn 11int n;long long a[maxn];long long m, mm;long long f1 (long long x) { long long ans = 0; for (int i = n; i >= 0; i--) { long long cur = 1; for (int j = 0; j < i; j++) cur *= x, cur %= m; ans += cur*a[i]; ans = (ans%m+m)%m; } return ans;}long long f2 (long long x) { long long ans = 0; for (int i = n; i >= 0; i--) { long long cur = 1; for (int j = 0; j < i; j++) cur *= x, cur %= mm; ans += cur*a[i]; ans = (ans%mm+mm)%mm; } return ans;}int main () { //freopen ("in.txt", "r", stdin); int t, kase = 0; scanf ("%d", &t); while (t--) { scanf ("%d", &n); for (int i = n; i >= 0; i--) { scanf ("%lld", &a[i]); } scanf ("%lld", &m); mm = m*m; printf ("Case #%d: ", ++kase); long long x, ans; for (x = 0; x < m; x++) { if (f1 (x) == 0) { for (ans = x; ans < m*m; ans += m) { if (f2 (ans) == 0) { printf ("%lld\n", ans); goto out; } } } } printf ("No solution!\n"); out: ; } return 0;}
0 0
- HDU 4569 (推导)
- hdu 1046 数学公式推导
- hdu 1049 数学公式推导
- HDU 4919 (数学推导)
- hdu 5000 dp+推导结论
- hdu 1719 Friend 数学推导
- HDU 5312(数学推导+技巧)
- hdu 5312 Sequence【数学推导】
- HDU 5826 (物理公式推导)
- HDU-5826-physics-数学推导
- HDU 2298 Toxophily(公式推导)
- Hdu 2086 A1=?公式csflx推导
- hdu 4349 lucas定理的推导
- hdu 4652 经典概率题+公式推导
- hdu 4565 公式推导+矩阵快速幂
- hdu 4992 Primitive Roots(推导+证明)
- hdu 5073 Galaxy (数学+推导)
- HDU 5312-Sequence(三角形数+推导)
- STL中的set容器的一点总结
- Color Constancy 色彩恒常性(1)White Patch Retinex
- CNTK从入门到深入研究(9) - CNTK工程结构(Extensibility&Reader Plugins)
- JAVA容器效率分析表,很全面(List,Map,Set)
- Java并发编程:Callable、Future和FutureTask
- HDU 4569 (推导)
- 逆波兰表达式的实现(也叫后缀表达式)
- Oracle中如何把表和索引放在不同的表空间里
- 不要随便在UI界面SystemClock.sleep,会造成卡顿
- 72 模板(四)
- backbone ——find方法应用
- Java基础学习第四天——选择与循环结构
- Centos下zookeeper安装配置
- 今天开始把一些心得记录下来!