您的位置:首页 > 其它

[随机化] HDU 5478 Can you find it

2016-07-13 16:31 316 查看
可以发现一个a对应一个b

枚举a 

n=1时求出b

然后随机化验证是否恒成立

#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;

ll P,k1,k2,b1;

inline ll Pow(ll a,int b){
ll ret=1;
for (;b;b>>=1,a=a*a%P)
if (b&1)
ret=ret*a%P;
return ret;
}

inline bool check(ll a,ll b){
int Test=300;
while (Test--)
{
int n=rand()%P+1;
if ((Pow(a,(k1*n+b1)%(P-1))+Pow(b,(k2*(n-1)+1)%(P-1)))%P!=0)
return 0;
}
return 1;
}

int main()
{
int a,b,_t=0;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
while (~scanf("%lld%lld%lld%lld",&P,&k1,&b1,&k2))
{
int flag=0;
printf("Case #%d:\n",++_t);
for (int i=1;i<P;i++)
{
a=i; b=P-Pow(a,k1+b1);
if (check(a,b))
flag=1,printf("%d %d\n",a,b);
}
if (!flag) printf("-1\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: