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

题目:

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. html5 canvas绘制圆形印章,以及与页面交互

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. alibaba的COBAR真是强大.

    近好不容易抽空研究了下Cobar,感觉这个产品确实很不错(在文档方面比Amoeba强多了),特此推荐给大家.Cobar是阿里巴巴研发的关系型数据 的分布式处理系统,该产品成功替代了原先基于Oracle ...

  3. 【原创】Mvc学习笔记(1)

    1.新建MVC4项目 在MVC4中有App_Data文件夹,这个文件夹里可以放一些重要的数据,比如说数据库的mdf文件等等,这个文件夹非常安全,因为这个文件夹不允许被别人下载,不允许被浏览器访问. A ...

  4. Java Fx-安装E(FX)CLIPSE IDE

    安装E(FX)CLIPSE IDE 本文主要介绍如何在Eclipse Mars 4.5.0版本上安装e(fx)clipse. 本文中的介绍和截图使用了纯净安装的为RCP和RAP开发者准备的Eclips ...

  5. OC与JS交互前言-b

    一.WebView加载HTML UIWebView提供了三个方法来加载html资源 1. loadHTMLString:baseURL: 把html文件的内容以字符串的形式加载到webView里面,然 ...

  6. [问题]编译报错:clang: error: linker command failed with exit code 1及duplicate symbol xxxx in错误解决方法之一

    今天添加了一个新类(包括m,h,xib文件),还没有调用,-编译遇到如下错误,根据错误提示, duplicate symbol param1 in: /Users/xxxx/Library/Devel ...

  7. Ajax、Comet、HTML 5 Web Sockets技术比较分析

    最近因为考虑研究B/S结构网站即时消息处理 参考了 JAVA怎么样实现即时消息提醒http://bbs.csdn.net/topics/330015611http://www.ibm.com/deve ...

  8. [Leetcode] Validate BST

    给一个Binary Tree,检查是不是Binary Search Tree. 即是否满足对每个节点,左子树的中的所有节点的值 < 当前节点的值 < 右子树所有节点的值. Solution ...

  9. csu 10月 月赛 F 题 ZZY and his little friends

    一道字典树异或的题,但是数据比较水,被大家用暴力给干掉了! 以前写过一个类似的题,叫做the longest xor in tree: 两个差不多吧! 好久没写字典树了,复习一下! 代码: #incl ...

  10. Codeforces Round #198 (Div. 2) —— B

    B题是一个计算几何的题,虽然以前看过计算几何的ppt,但一直都没有写过: 昨晚比赛的时候本来想写的,但是怕不熟练浪费时间,太可惜了! 其实没必要选出一个最大的矩形: 以矩形的一条对角线为轴,向上或者向 ...