分析:如果 f(x)%(p2)=0 那么一定有 f(x)%p=0 ,如果后者不成立,那么前者一定不成立;如果 f(x)%p=0 那么一定有 f(x+p)%p=0 。
AC 代码:
/*************************************************************************
> File Name: test.cpp
> Author: Akira
> Mail: qaq.febr2.qaq@gmail.com
************************************************************************/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <ctime>
#include <climits>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;
#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
LL B[8], pri;
LL deg;
LL f(LL x, LL mod)
{
LL sum=0,ans=1;
for(int i=0;i<=deg;i++)
{
sum = (sum+B[i]*ans)%mod;
ans *= x;
}
return (sum+mod)%mod;
}
int main()
{
//std::ios::sync_with_stdio(false);
int T;
scanf("%d", &T);
for(int t=1;t<T;t++)
{
scanf("%lld", °);
for(int i=deg;i>=0;i--) scanf("%lld", &B[i]);
scanf("%lld", &pri);
LL ans = -1;
for(LL i=0;i<=pri;i++)
{
if(f(i,pri)!=0) continue;
for(LL j=i;j<=pri*pri;j+=pri)
{
if(f(j,pri*pri)==0)
{
ans = j;
break;
}
}
if(ans!=-1) break;
}
if(ans==-1) printf("Case #%d: No solution!\n", t);
else printf("Case #%d: %lld\n", t, ans);
}
//system("pause");
}