HDU 5478 Can you find it

Source: Internet
Author: User

Can you find it

Time limit:8000/5000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 208


Problem Descriptiongiven a prime numberC(1≤C≤x10) , and three integers K1, B1, K2(1≤K1,K2,B1≤10) . Please find all pairs (A, B) which satisfied the equationAk⋅ Nb1 +Bk⋅ Nk+1 = 0 (mod C) (n = 1, 2, 3, ...).

Inputthere is multiple test cases (no more than 30). For each test, a single line contains four integers C, K1, B1, K2.

Outputfirst, please output ' case #k: ', K is the number in test case. See sample output for more detail.
Please output the pairs (A, B) in lexicographical order. (1a,b<c. If There is not a pair (a, b), please output-1.

Sample Input23 1 1 2

Sample outputcase #1:1 22

Source ACM/ICPC Asia Regional Shanghai Online

Recommendhujie first wants N to be ... Must be set up, so first ensure that n=1 set up, and then verify that the other is established, the equation to the left of the B that one to the right, except for a moment, found that each increment is a^k1 and b^k2 so long as the n=2 set up, the back of the establishment. Don't be afraid of the problem next, or you can do it.
#include <queue>#include<math.h>#include<stdio.h>#include<string.h>#include<string>#include<iostream>#include<algorithm>using namespacestd;#defineN 1234567#defineM 12intC, K1, B1, K2;BOOLFlag;intQuickpow (intMintNintK//m^n% k{    intb =1;  while(N >0)    {          if(N &1) b= (b*m)%K; N= N >>1 ; M= (m*m)%K; }    returnb;}intMain () {inttt =1;intb;  while(~SCANF ("%d %d%d%d", &c, &k1, &AMP;B1, &K2)) {printf ("Case #%d:\n", tt++); Flag=0;  for(intA =1; a < C; a++) {b= C-quickpow (a,k1+b1,c); if(Quickpow (A, k1*2+B1, C) + Quickpow (b, k2*2-k2+1, c))%c = =0) {printf ("%d%d\n", A, b); Flag=1; }        }        if(Flag = =0) printf ("-1\n"); }    return 0;}

HDU 5478 Can you find it

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.