For two numbers, the example of the first number is 10 ^ 100, the second number is 10 ^ 6, and the first number is the product of the two prime numbers, ask if the number that does not exceed the second number is the factor of the first tree.
Idea: 10 ^ 6 contains only 7 W + prime numbers. You only need to judge one by one whether it can be divisible. Then the prime number of this question must be linear, otherwise it will be T. In addition, I pressed four digits at the beginning of high precision, and then wa. After a long call, I found that int exists in the Process of Division determination. I changed it to long, which means T. At last, I was very angry, directly pressed to seven places, decisive A, as if time is not slow. If you want to use an int, you can only press three digits at most.
Code:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 1001000using namespace std;struct BigInt{int num[1010],len;BigInt(char *s) {memset(num,0,sizeof(num));int length = strlen(s + 1);len = 0;for(int i = length; i > 0; i -= 7) {int p = 1;++len;for(int j = 0; j <= 6 && i - j > 0; ++j) {num[len] += (s[i - j] - '0') * p;p *= 10;}}}bool Divide(int x) {long long remain = 0;for(int i = len; i; --i)remain = (remain * 10000000 + num[i]) % x;return !remain;}};int prime[MAX],primes;bool notp[MAX];char src[10010];int L;void Pretreatment(){for(int i = 2; i < MAX; ++i) {if (!notp[i])prime[++primes] = i;for(int j = 1; j <= primes && prime[j] * i < MAX; ++j) {notp[prime[j] * i] = 1;if (i % prime[j] == 0)break;}}}int main(){Pretreatment();while(scanf("%s%d",src + 1,&L),L) {BigInt p(src);bool flag = false;for(int i = 1; i <= primes && prime[i] < L; ++i)if(p.Divide(prime[i])) {flag = true;printf("BAD %d\n",prime[i]);break;}if(!flag)puts("GOOD");}return 0;}
Poj 2635 the embarrassed cryptographer linear screen + high precision modulo