113 - Power of Cryptography


Power of Cryptography 
Background
Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers modulo functions of these primes. Work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered to be of only theoretical interest.
This problem involves the efficient computation of integer roots of numbers.
The Problem
Given an integer  and an integer  you are to write a program that determines  , the positive root of p. In this problem, given such integers n and p, p will always be of the form  for an integerk (this integer is what your program must find).
The Input
The input consists of a sequence of integer pairs n and p with each integer on a line by itself. For all such pairs  ,  and there exists an integer k,  such that  .
The Output
For each integer pair n and p the value  should be printed, i.e., the number k such that  .
Sample Input
2
16
3
27
7
4357186184021382204544

Sample Output
4
3
1234

           ,       。。    POJ   discuss,         。。
          。。。   UVa OJ  RE ,   POJ  AC 。。

  。。。。     double     。。
    float double         http://blog.sina.com.cn/s/blog_6f901d67010189nh.html

float double 。

1.   float double 。   float 8 , double 11 , :   float:   1bit( ) 8bits( ) 23bits( )   double:   1bit( ) 11bits( ) 52bits( )    ,float -127~+128, double -1023~+1024, 。    ; , 。   float -2^128 ~ +2^128, -3.40E+38 ~ +3.40E+38;double -2^1024 ~ +2^1024, -1.79E+308 ~ +1.79E+308。

2.     float double 。 , “1”, , 。   float:2^23 = 8388608, , 7 , 6 , float 6~7 ;   double:2^52 = 4503599627370496, 16 , ,double 15~16 。

/*
//       。。  discuss       +   。。。
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<ctype.h>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
char p[120];
int num(int mid)
{
    int ji[120]= {0},chen[12]= {0};
    int i,j,len=0;
    while(mid)
    {
        chen[len++]=mid%10;
        mid/=10;
        ji[len-1]=chen[len-1];
    }
    int LEN=len;
    for (int t=0; t<n-1; t++)
    {
        int ji_copy[120]={0};
        for (i=0; i<len; i++)
            for (j=0; j<LEN; j++)
            {
                ji_copy[i+j]+=chen[i]*ji[j];
                if (ji_copy[i+j]>9)
                {
                    ji_copy[i+j+1]+=ji_copy[i+j]/10;
                    ji_copy[i+j]=ji_copy[i+j]%10;
                }
            }
        int k=len+LEN+3;
        while(ji_copy[k]==0) k--;
        LEN=k+1;
        for (i=0; i<LEN; i++)
            ji[i]=ji_copy[i];
    }
    if (LEN<strlen(p)) return 1;
    else if (LEN>strlen(p)) return -1;
    else
    {
        char p_fight[120];
        j=0;
        for (i=LEN-1; i>=0; i--)
            p_fight[j++]=ji[i]+'0';
        p_fight[j]='\0';
        return strcmp(p,p_fight);
    }
}
int binary_search(int wei)
{
    int top,mid,bot,i;
    bot=pow(10,wei-1);
    top=pow(10,wei);
    while(bot<=top)//   =  ,       
    {
        mid=(bot+top)/2;
        int temp=num(mid);
        if (temp>0)
            bot=mid+1;
        else if (temp<0)
            top=mid-1;
        else break;
    }
    return mid;
}
int main ()
{
    int wei;
    while(cin>>n)
    {
        memset(p,0,sizeof(p));
        getchar();
        gets(p);
        int len=strlen(p);
        int tt;
        tt=len/n;
        if (tt*n-len==0) wei=tt;
        else wei=tt+1;
        int mid=binary_search(wei);
        cout<<mid<<endl;
    }
    return 0;
}
*/

//double    
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main ()
{
    double k,n,p;
    while(scanf("%lf%lf",&n,&p)!=EOF)
    {
        printf("%.0lf
",pow(p,(1/n))); } return 0; }