"HDU2815" "Expand Bsgs" Mod Tree

Source: Internet
Author: User

Problem Description
The picture indicates a tree and every node has 2 children.
The depth of the nodes whose color is blue is 3; The depth of the node whose color is pink is 0.
Now out problem was so easy and give you a tree that every nodes has K children, you were expected to calculate the Minimize D Epth d So, the number of nodes whose depth is D equals-N after mod P.

Inputthe input consists of several test cases.
Every cases has only three integers indicating K, p, N. (1<=k, p, n<=10^9)

Outputthe Minimize D.
If you can ' t find such D, just output "orz,i can ' t find d!"

Sample Input3 78992 4534 1314520 655365 1234 67

Sample Outputorz,i can ' t find d!820

Authoraekdycoin Source HDU 1st "Old-vegetable-birds Cup" programming Open Contest Recommendlcy | We have carefully selected several similar problems for you:2814 2809 3037 2447 2810 "Analysis" normal bsgs is only able to solve a^x = B (mod c), where C In the form of prime numbers, and through the online elimination of the method can solve this problem. It is also possible for the same bsgs to directly solve the form of C as prime number.
1 /*2 The Song Dynasty's anchor several way3 "The birth of the son, crazy Flower Instant Fragrance"4 Crazy Flower instant fragrant, late butterfly lingering meaning. Days and short causes, gathering and parting often easy. 5 sung into the sound, annoyed and disorderly double moth Cui. The wanderer is unbearable to smell, is the affair. 6 */ 7#include <iostream>8#include <cstdio>9#include <ctime>Ten#include <cmath> One#include <algorithm> A#include <cstring> -#include <string> -#include <map> the#include <Set> -#include <vector> - #defineLOCAL - Const intMAXN = ++Ten; + Const intINF =0x7fffffff; - using namespacestd; +typedefLong LongLL; A  at intgcdintAintb) {returnb = =0? A:GCD (b, a%b);} - intEXT_GCD (intAintBint&x,int&y) { -     if(b = =0) {x =1; y =0;returnA;} -     intTMP = EXT_GCD (b, a%b, y, x); -Y-= x * (A/b); -     returntmp; in } - //solving to intInval (intAintBintN) { +     intx, Y, E; - EXT_GCD (A, n, x, y); theE = (LL) x * b% n;//be careful beyond the range of int, because A,n is coprime, so the solution is ax + NY = 1, multiplied by B for the correct answer *     returnE <0? E +n:e; $ }Panax Notoginseng //k S M - intPow_mod (LL A,intBintc) { the     if(b = =1)returnAC; +LL tmp = Pow_mod (A, B/2, c); A     if(b%2==0)return(TMP * tmp)%C; the     Else return((TMP * tmp)% c) * a)%C; + } - intBSGS (intAintBintC) { $map<int,int> H;//Hash $LL buf =1% C, D =buf, K; -     intD =0, TMP; -     //Small Steps the      for(inti =0; I <= -; BUF = buf * A% C, i++) -     if(buf = = B)returni;Wuyi     //Elimination Factor the      while(TMP = GCD (A, C))! =1){ -           if(B% gcd (A, C)! =0)return-1;//to understand the indefinite equation Wud++; -C/=tmp; AboutB/=tmp; $D = d * a/tmp%C; -     } - h.clear (); -     intM = (int) Ceil (sqrt (C *1.0)); ABUF =1%C; +      for(inti =0; I <= M; BUF = buf * A% C, i++) the     if(H.find (int) buf) = = H.end ()) h[(int) BUF] = i;//Hash -      $K =pow_mod (LL) A, M, C); the      for(inti =0; I <= M; D = d * K% C, i++){ theTMP = Inval (int) D, B, C);//D and C are coprime. the         //You must not forget the last D . the         if(TMP >=0&& h.find (tmp)! = H.end ())returnI * M + h[tmp] +D; -     }  in     return-1;//I can't find them . the }  the intMain () { About      the     //Convert to A^x = B (mod C) Form the     intA, B, C; the      while(SCANF ("%d%d%d", &a, &c, &b)! =EOF) { +           if(B >= C) {printf ("Orz,i can ' t find d!\n");Continue;}//233 -           intTMP =bsgs (A, B, C); the           if(TMP <0) printf ("Orz,i can ' t find d!\n");Bayi           Elseprintf"%d\n", TMP); the     } the     return 0; - } -  the  
View Code

"HDU2815" "Expand Bsgs" Mod Tree

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.