POJ2635 The Embarrassed Cryptographer simple number theory
I am also drunk when I see this question ~ Q: Give You A k, which is the product of two prime numbers, then give a number L, and find out which two prime numbers are multiplied by k, whether or not the smaller prime number is smaller than L. If it is smaller than L, it will output BAD plus the smaller prime number. Otherwise, it will output "GOOD ",
I just got this question, but I didn't see it clearly when I got it. At first, I had a lot of trouble with K. If I wanted to find out the two prime numbers, it would be impossible because there was always a huge one, check whether a prime number is within 10 ^ 6, but at that time I think it is necessary to prove that the value of k/prime must also be a prime number to meet the requirements, in fact, all the questions have been stipulated that k must be the product of two prime numbers and will not be composed by the multiplication of other union numbers, so it is much simpler.
I don't know what the theorem is, but for a long number such as 123456789, if each number on it exists in the array num, 123456789% m is equal
Int now = 0;
For (int I = 0; I <9; I ++) now = (now * 10 + num [I]) % m;
If you know this, you can do it. K can actually be converted to a large number in an array. For example, if you convert K to a thousand hexadecimal number, save it first, at the end of the calculation, multiply the value by one thousand or 10 thousand. The for above is relative to the decimal number. Change now * 10 to the corresponding hexadecimal number. for the remaining enumerated prime numbers, you only need to print the prime number table, at first, I was afraid that K could not be stored, but I didn't go into the ten-in-one system directly without computation. The result was always WA, and then it would be too much to convert it to the ten-in-one system, the reason is that when the remainder is obtained for a for loop, the remainder can be up to 10 ^ 6, and then multiplied by 10000, The int Is burst, and then changed to long, which is converted to the hichina system, it is also possible.
string s;int L;int nnum[100000 + 5];int cnt ;bool isprime[1000000 + 55];int prime[1000000 + 55];int k;void make_prime() {memset(isprime,false,sizeof(isprime));for(int i=2;i<1000055 ;i++)if(!isprime[i])for(int j=i*2;j<1000055;j+=i)isprime[j]=true;for(int i=2;i<1000055;i++)if(!isprime[i])prime[k++]=i;}void init() {memset(nnum,0,sizeof(nnum));cnt = 0;}bool input() {while(cin>>s>>L) {if(s == 0 && L == 0)break;return false;}return true;}void slove() {int len = s.length();for(int i=len - 1;i >= 0;i-=3) {for(int j= i - 2;j<=i;j++) {if(j < 0)j = 0;nnum[cnt] = nnum[cnt] * 10 + s[j] - '0';}cnt++;}}bool gao(int x) {int ret = 0;for(int i= cnt - 1;i>=0;i--) {ret = (ret * 1000 + nnum[i])%x;}if(ret)return false;return true;}void cal() {slove();for(int i=0;i