POJ2635 the embarrassed cryptographer simple number theory

Source: Internet
Author: User

Topic links

See this problem is also drunk ~ Test instructions: give you a K, he is the product of two primes, and then give a number L, and then find out which two prime numbers multiplied by equal to K, the smaller that prime number is less than L, if less than L on the output "bad" plus the smaller prime number, otherwise the output "good",

Just get this topic, some of the test instructions not see clearly, a start tangled in K very big, if want to find out two prime number is impossible, because there is always a very big big, find out whether one prime number in 10^6 is can, but at that time I think also need to prove k/prime The value must also be a prime number to meet the requirements, in fact, the topic is stipulated that K must be two primes of the product and will not be multiplied by other composite composition, so it is a lot easier

I don't know what the theorem is, but for a very long number like 123456789, if you put it on every digit in the array num, 123456789%m is equal to

int now = 0;

for (int. i=0;i<9;i++) now = (now * + num[i])%m;

If you know this is good to do, for K can actually be converted into large binary numbers exist in the array, such as the conversion into a binary system, first preserved, and then multiplied by 1000 or 10,000, the top of the for is relative to the decimal, the now*10 to the corresponding binary can be changed, The remainder of the enumerator only need to print the prime number of the table, a start afraid K too big can not go down and not to be directly converted into million, the result has been WA, and later converted to the thousand system is over, because the remainder of the for loop when the surplus up to 10^6, and then multiply 10000 will explode int, And then changed to a long long, converted into a universal, but also can be too

String S;int l;int nnum[100000 + 5];int cnt; bool isprime[1000000 + 55];int prime[1000000 + 55];int k;void make_prime () {m Emset (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;nnu M[CNT] = nnum[cnt] * ten + s[j]-' 0 ';} cnt++;}} BOOL Gao (int x) {int ret = 0;for (int i= cnt-1;i>=0;i--) {ret = (ret * + nnum[i])%x; if (ret) return False;return true;} void Cal () {slove (); for (int i=0;i<k && prime[i] < l;i++) {if (Gao (Prime[i])) {printf ("Bad%d\n", Prime[i]); return;}} Puts ("good");} void output () {}int main () {make_prime (); while (true) {init (); if (input ()) return 0;cal (); output ();} return 0;}



POJ2635 the embarrassed cryptographer simple number theory

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.