Ultraviolet A-113 Power of Cryptography (Power of a Large Number + two points)

Source: Internet
Author: User

Ultraviolet A-113 Power of Cryptography (Power of a Large Number + two points)

Open Link

Given n and p, find k to make k ^ n = p. 1 <= k <= 10 ^ 9

We can use a second k to express k ^ n with high precision and then compare it with p.

 

# Include
 
  
# Include
  
   
# Include
   
    
Const int maxn = 1000000000; struct bign {int len; int f [1500]; bign () {memset (f, 0, sizeof (f )); len = 0 ;}}; int n, ans; char p [150]; bign mul (bign a, bign B) // multiply the large numbers by {bign c; for (int I = 0; i0) {. f [l] = B. f [l] = x % 10; x/= 10; l ++;}. len = B. len = l; for (int I = 1; I
    
     
L) return-1; else {for (int I = 0; I
     
      
P [I]-'0') {flag =-1; break;} else {. len -- ;}} return flag ;}} void binary (int x, int y) // binary k between x and y {bign a; while (x <= y) {int mid = (x + y)/2; a = solve (mid); int t = compare (a); if (t = 0) {ans = mid; return;} else if (t = 1) x = mid + 1; else y = mid-1;} int main () {// freopen ("a.txt ", "r", stdin); while (~ Scanf ("% d", & n) {getchar; scanf ("% s", p); binary (1, maxn); printf ("% d \ n ", ans);} return 0 ;}
     
    
   
  
 

Of course, the faster method is to directly use double.

 

 

#include
 
  #include
  
   int main(){    double n,p;    while(~scanf("%lf%lf",&n,&p))    {        printf("%.0lf\n",pow(p,1.0/n));    }    return 0;}
  
 


 

 

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.