Description
The young and very promising cryptographer Odd Even has implemented the security module of a large system with thousands of users, which is now in use in his company. The cryptographic keys are created from the product of two primes, and are believed to be secure because there is no known method for factoring such a product effectively.
What Odd Even did not think of, was that both factors in a key should be large, not just their product. It is now possible that some of the users of the system have weak keys. In a desperate attempt not to be fired, Odd Even secretly goes through all the users keys, to check if they are strong enough. He uses his very poweful Atari, and is especially careful when checking his boss’ key.
【题目分析】
表示图不错,大概就是问一个数是不是有1-t之间的质因子。然后就是线性筛筛出质数,然后就可以快速的判断,从高位到低位边进位边除。然后就可以了,不过要注意必须压位储存,否则会T掉的。
【代码】
#include <cstdio>
#include <cstring>
int pri[1000001],top=0,x;
bool phi[1000001];
char s[101];
inline void init()
{
for (int i=2;i<=1000000;++i)
{
if (!phi[i]) pri[++top]=i;
for (int j=1;j<=top;++j)
{
if (pri[j]*i>=1000000) break;
phi[pri[j]*i]=true;
if (i%pri[j]==0) break;
}
}
}
int main()
{
init();
// printf("yes\n");
while (scanf("%s%d",s+1,&x)&&x)
{
int l=strlen(s+1);
int flag=0;
for (int i=1;i<=top&&pri[i]<x;++i)
{
int n=0,j;
for (j=1;j+2<=l;j+=3)
(n=n*1000+((s[j]-'0')*100+(s[j+1]-'0')*10+(s[j+2]-'0')))%=pri[i];
if (j==l-1) (n=n*100+(s[j]-'0')*10+(s[j+1]-'0'))%=pri[i];
if (j==l) (n=n*10+s[j]-'0')%=pri[i];
if (!n)
{
flag=1;
printf("BAD %d\n",pri[i]);
break;
}
}
if (!flag) printf("GOOD\n");
}
}
1380

被折叠的 条评论
为什么被折叠?



