//只用一行核心代码就可以过的天坑题目............= =

题目:

Description

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
 
哎~不多说了,代码如下:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double n,p;
while(cin>>n>>p)
{
cout<<pow(p,/n)<<endl;
}
return ;
}

 正解:二分+高精
代码:
 #include <stdio.h>
#include <string.h> // 交换字符串函数
void swap_str(char str[]) {
int len = strlen(str);
for (int i=; i<len/; i++) {
int tmp = str[i];
str[i] = str[len-i-];
str[len-i-] = tmp;
}
} // 大数与整型相乘函数(大数以字符串形式给出)
void my_mul(char str[], int x) {
int len = strlen(str);
int cp = , i, tmp;
swap_str(str);
for (i=; i<len; i++) {
tmp = (str[i]-'')*x + cp;
str[i] = (tmp%) + '';
cp = tmp / ;
}
while (cp) {
str[i++] = (cp%) + '';
cp /= ;
}
while (''==str[i-] && i>)
i--;
str[i] = '\0';
swap_str(str);
}
// 比较两个大数的大小(大数前没有0)
int my_numCmp(char str1[], char str2[]) {
int len1, len2;
len1 = strlen(str1);
len2 = strlen(str2);
if (len1 > len2)
return ;
if (len1 < len2)
return -;
return strcmp(str1, str2);
} // 字符串存储开方结果
void my_pow(char str[], int k, int n) {
str[] = '', str[] = '\0';
while (n--) {
my_mul(str, k);
}
} // 二分查找正确答案
int my_binary_search(int n, char str[]) {
int high = 1e9, low = ;
int mid;
char tot[]; while (low < high) {
mid = low + (high-low)/;
my_pow(tot, mid, n);
int tmp = my_numCmp(tot, str);
if ( == tmp)
return mid;
if (tmp < )
low = mid + ;
else
high = mid;
}
return mid;
} int main() {
char str[];
int n;
while (scanf("%d%s", &n, str) != EOF) {
printf("%d\n", my_binary_search(n, str));
}
return ;
}

代码来源:http://blog.csdn.net/zcube/article/details/8545523

Power of Cryptography的更多相关文章

  1. [POJ2109]Power of Cryptography

    [POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...

  2. Power of Cryptography(用double的泰勒公式可行分析)

    Power of Cryptography Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  3. 贪心 POJ 2109 Power of Cryptography

    题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...

  4. poj 2109 Power of Cryptography

    点击打开链接 Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16388   Ac ...

  5. UVA 113 Power of Cryptography (数学)

    Power of Cryptography  Background Current work in cryptography involves (among other things) large p ...

  6. Poj 2109 / OpenJudge 2109 Power of Cryptography

    1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...

  7. POJ2109——Power of Cryptography

    Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...

  8. POJ 2109 :Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18258   Accepted: ...

  9. POJ 2109 -- Power of Cryptography

    Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 26622   Accepted: ...

  10. POJ 2109 Power of Cryptography 数学题 double和float精度和范围

    Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...

随机推荐

  1. HTML新元素

    <canvas> 标签定义图形,比如图表和其他图像.该标签基于 JavaScript 的绘图 API <audio> 定义音频内容 <video> 定义视频(vid ...

  2. c#反射机制判断同一个类的两个实例的值是否完全一样

    ; i < properties1.Length; i++)            {                string s = properties1[i].DeclaringTyp ...

  3. uboot的mkconfig分析

    uboot的mkconfig是一个shell脚本.对于笔者这种Linux学习初学者,不太可能认真的把shell脚本学习一遍.但是,倘若不能理解mkconfig的含义,又很难从整体的理解uboot(我认 ...

  4. JavaScript高级之函数的四种调用形式

    主要内容 分析函数的四种调用形式 弄清楚函数中this的意义 明确构造函对象的过程 学会使用上下文调用函数 了解函数的调用过程有助于深入学习与分析JavaScript代码. 本文是JavaScript ...

  5. PHP练习题(二)

    程序6.题目: 假设某人有100,000现金,每经过一次路口需要进行一次交费交费规则为当他现金大于50,000时每次需要交%5,如果现金小于等于50,000时每次交5,000.问此人可以经过多少次这个 ...

  6. linux下的ImageMagick安装方法

     linux下的ImageMagick安装方法  由于没有图形化界面的支持,在Linux(CentOS 6.4 x64)上的配置相对Windows XP还是麻烦了一点.   1.下载ImageMagi ...

  7. 对SVM的个人理解

    对SVM的个人理解 之前以为SVM很强大很神秘,自己了解了之后发现原理并不难,不过,“大师的功力在于将idea使用数学定义它,使用物理描述它”,这一点在看SVM的数学部分的时候已经深刻的体会到了,最小 ...

  8. hdu 1269

    强连通分量题,用tarjin算法: 这是一道很简单的tarjin算法题,基本上就是套模板: 贴代码: #include<cstdio> #include<vector> #in ...

  9. 任正非:华为三十年大限快到了 想不死就得新生(建立战略预备队)cool

    华为心声社区官方微信今日发布了任正非8月15日在华为公司内部做的关于战略预备队建设汇报的讲话.讲话内容中提到,华为公司需要组织.结构.人才等所有一切都变化,通过变化使新的东西成长起来.   任正非表示 ...

  10. C# 读取网络txt文件 并写在本地txt文件中

    public void WriteStream() { try { stirng ImagesPath = ImagesPath + "\\2013-09-27.txt"; Htt ...