Special equations
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 206 Accepted Submission(s): 108
Special Judge
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 a n to a 0 (0 < abs(a n) <= 100; abs(a i) <= 10000 when deg >= 3, otherwise abs(a i) <= 100000000, i<n). The last integer is prime pri (pri<=10000).
Remember, your task is to solve f(x) 0 (mod pri*pri)
题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有f(x+p)%p=0。
所以我们可以开始从0到p枚举x,当f(x)%p=0,然后再从x到p*p枚举,不过每次都是+p,找到了输出即可,没有的话No solution!,这里只需要枚举到pri*pri,这个证法和前面的一样
#include<stdio.h> int a[6],pri,n; __int64 getf(int x,int i) { int j; __int64 sum=0; for(j=0;j<i;j++) { sum=(sum+a[j])*x; } return sum+a[j]; } void solve() { int i,j,k; int pri2=pri*pri; for(i=0;i<pri;i++) { if((getf(i,n))%pri==0) { for(j=i;j<pri2;j+=pri) { if(getf(j,n)%pri2==0) { printf("%d\n",j); return ; } } } } printf("No solution!\n"); } int main() { int i,j,k,t,no; __int64 temp; scanf("%d",&t); for(k=1;k<=t;k++) { scanf("%d",&n); for(i=0;i<=n;i++) { scanf("%d",&a[i]); } scanf("%d",&pri); printf("Case #%d: ",k); solve(); } return 0; }