Poj 2635 the embarrassed cryptographer linear screen + high precision modulo

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.