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

题目:

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. javascript 节点的增,删,改,查

    1.创建节点  A.创建元素节点    document.createElement("元素标签名");   B.创建属性节点    document.createAttribut ...

  2. 数据库创建&数据表创建

    --第2_1题创建数据库 create database Student201038897041 on primary (name='student1', filename='F:\coures\SQ ...

  3. php中getimagesize函数的用法

    php获取图片信息getimagesize,php自带函数.获取图片的类型,尺寸的方法有许多,该函数仅是方法之一. getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC ...

  4. linux安装ruby ruby-devel rubygems bundler

    linux安装ruby ruby-devel rubygems yum install ruby ruby-devel rubygems 安装bundler gem install bundleror ...

  5. C++ 11 笔记 (二) : for循环

    首先肯定的是,我不是标题党.. C++11的for循环确实有跟C++98不一样的地方,还是先上代码: , , , , }; for (int x : test_arr) { std::cout < ...

  6. VS2010升级VS2012必备(MVC4 WebPage2.0 Razor2.0资料汇集)

    刚把项目升级到2012,发现发生了很多变化,以下是最近看过的网站和资料汇集,供需要者参考. 本文在最近一个月可能会不断更新. Razor2.0 新特性介绍: 介绍1:http://vibrantcod ...

  7. [原博客] BZOJ 2242 [SDOI2011] 计算器

    题目链接 noip级数论模版题了吧.让求三个东西: 给定y,z,p,计算`Y^Z Mod P` 的值. 给定y,z,p,计算满足`xy≡ Z ( mod P )`的最小非负整数. 给定y,z,p,计算 ...

  8. Gabor变换

    Gabor变换 Gabor变换属于加窗傅立叶变换,Gabor函数可以在频域不同尺度.不同方向上提取相关的特征.另外Gabor函数与人眼的生物作用相仿,所以经常用作纹理识别上,并取得了较好的效果.Gab ...

  9. 【技术贴】解决Mysql启动服务报错1067 进程意外终止

    无法启动MYSQL服务错误1067 进程意外终止. 我使用2013-10-25_appserv-win32-2.6.0.exe安装的MySql,结果服务起不来. 于是细心机智的我发现,在F:\stud ...

  10. HTML5解决跨域问题

    HTML5解决跨域问题 由于浏览器的同源策略,网络连接的跨域访问是不被允许的,XHR对象不能直接与非同源的网站处理数据交互.而同源指的是什么呢?同源的范畴包括:规则(协议),主机号(域名.ip等),端 ...