Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among 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 only of theoretical interest. 
This problem involves the efficient computation of integer roots of numbers. 
Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the n th. power, for an integer k (this integer is what your program must find).


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 1<=n<= 200, 1<=p<10 101 and there exists an integer k, 1<=k<=10 9 such that k n = p.


Output

For each integer pair n and p the value k should be printed, i.e., the number k such that k n =p.


Sample Input

2 16
3 27
7 4357186184021382204544

Sample Output

4
3
1234
题意:给出n和p(n<=200,p<=10^101),求方程k^n=p的k的正整数解,保证k<=10^9 题解:这道神题传说有非常神奇的解f♂a

   然而并没有什么卵用,你只会收到一连串的WA

   该题的意图应该是贪心,至于怎么贪……わかない……

好吧,我太菜了,只能用最暴力的方法,设x^y=p
对于y>n的解来说,x必然小于k
对于y<n的解来说,x必然大于k
对于x来说单调性
所以可以二分
至于y该怎么求……想必一个高精度的log就行了!而且只需要保留个位即可
感觉我的代码还是有问题的,但莫名1A了
代码如下
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; struct big
{
int len;
int num[];
}; int n; void trans(char* a,big &b)
{
memset(b.num,,sizeof(b.num));
int len=strlen(a);
for(int i=; i<len; i++)
{
b.num[len-i-]=a[i]-'';
}
b.len=len;
} void trans_(int a,big &b)
{
memset(b.num,,sizeof(b.num));
int len=;
while(a)
{
b.num[len++]=a%;
a/=;
}
b.len=len;
} void print(big a)
{
for(int i=a.len-; i>=; i--)
{
printf("%d",a.num[i]);
}
puts("");
} int comp(big x,big y)
{
if(x.len>y.len)
{
return ;
}
if(x.len<y.len)
{
return -;
}
for(int i=x.len-; i>=; i--)
{
if(x.num[i]>y.num[i])
{
return ;
}
if(x.num[i]<y.num[i])
{
return -;
}
}
return ;
} big sub(big a,big b)
{
big c;
int len=a.len;
int lenc=len;
for(int i=; i<len; i++)
{
c.num[i]=a.num[i]-b.num[i];
if(c.num[i]<)
{
c.num[i]+=;
a.num[i+]--;
}
}
while(c.num[lenc-]==&&lenc>)
{
lenc--;
}
c.len=lenc;
return c;
} void mul_ten(big &x)
{
int len=x.len;
len++;
for(int i=len-; i>=; i--)
{
x.num[i+]=x.num[i];
}
x.num[]=;
while(x.num[len-]==&&len>)
{
len--;
}
x.len=len;
} big div(big x,big y)
{
big f,m;
memset(f.num,,sizeof(f.num));
memset(m.num,,sizeof(m.num));
m.len=;
int len=x.len;
for(int i=x.len-; i>=; i--)
{
mul_ten(m);
m.num[]=x.num[i];
while(comp(m,y)!=-)
{
m=sub(m,y);
f.num[i]++;
}
}
while(f.num[len-]==&&len>)
{
len--;
}
f.len=len;
return f;
} int check(big x,big y)
{
big z;
int cnt=;
z.len=;
z.num[]=;
while(!comp(x,z)==)
{
if(comp(x,y)==-)
{
break;
}
cnt++;
x=div(x,y);
}
if(cnt<n)
{
return ;
}
else
{
return ;
}
} int main()
{
char b[];
int a;
big x,y;
while(scanf("%d %s",&n,b)==)
{
memset(x.num,,sizeof(x.num));
memset(y.num,,sizeof(y.num));
int l=,r=;
int mid;
trans(b,y);
while(l<r)
{
mid=(l+r)>>;
trans_(mid,x);
int flag=check(y,x);
if(flag)
{
l=mid;
}
else
{
r=mid-;
}
if(r-l<=)
{
trans_(r,x);
if(check(y,x))
{
printf("%d\n",r);
break;
}
else
{
printf("%d\n",l);
break;
}
}
}
}
}

 

最新文章

  1. 找不到方法:&quot;!!0[] System.Array.Empty()&quot;.
  2. HttpWebRequest出错 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF
  3. jQuery Ajax(异步请求)
  4. windows进程详解
  5. Android(Java):jni源代码
  6. Debian下的PPPOE服务器配置
  7. 闲话:你今天OO了吗?
  8. phpwind 去除init.phpwind.net统计功能
  9. git/github初级运用自如 (转)
  10. 在Mac OS 下 build Tesseract4.0 源码并在命令行中使用
  11. Windows桌面快捷图标上的小箭头的恢复
  12. MACE环境搭建
  13. Zabbix(二)
  14. 锋利的jQuery初学(1)
  15. win10 安装 face_recognition
  16. read()、write()返回 Input/output error, Device or resource busy解决
  17. Web侦察工具HTTrack (爬取整站)
  18. 【Ubuntu】PHP环境安装-phpstudy for linux版
  19. 题解——HDU 1848 Fibonacci again and again
  20. android 判断左右滑动,上下滑动的GestureDetector简单手势检测

热门文章

  1. Java 多个引用类型变量引用同一个对象
  2. 73个word使用终极技巧
  3. 经典ARP协议讲解,一定要看
  4. biosdevname网卡命名方式
  5. Spring Boot Oauth2
  6. zabbix 在linux上安装以及一些配置
  7. C#获取程序代码执行时长
  8. 013. MVC5过滤器
  9. AMF解析之数据类型定义 (转)
  10. 19-EasyNetQ:用EasyNetQ.Hosepipe重新提交错误信息