Power of Cryptography
//只用一行核心代码就可以过的天坑题目............= =
题目:
Description
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
Output
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 ;
}
Power of Cryptography的更多相关文章
- [POJ2109]Power of Cryptography
[POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...
- Power of Cryptography(用double的泰勒公式可行分析)
Power of Cryptography Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- 贪心 POJ 2109 Power of Cryptography
题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...
- poj 2109 Power of Cryptography
点击打开链接 Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16388 Ac ...
- UVA 113 Power of Cryptography (数学)
Power of Cryptography Background Current work in cryptography involves (among other things) large p ...
- 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 ...
- POJ2109——Power of Cryptography
Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...
- POJ 2109 :Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18258 Accepted: ...
- POJ 2109 -- Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 26622 Accepted: ...
- POJ 2109 Power of Cryptography 数学题 double和float精度和范围
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...
随机推荐
- 诡异的XmlSerializer属性字段Specified
自动生成代码时,往往会为一个字段假设为 * , 生成另一个bool型字段: *Specified: 如: [Serializable] public class A { [XmlElement] pu ...
- WinForm TreeView 三种状态
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { var node = e.N ...
- Cassandra1.2文档学习(1)——Cassandra基本说明
参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...
- HTML 表格的书写方式:
首先要进行reset table{border-collapse:collapse;border-spacing:0;}th{text-align:inherit;} 1. caption标签对整个 ...
- 常见排序算法(PHP实现)
function InsertSort($arr){ $num = count($arr); for($i = 1; $i < $num; $i++){ $key = $arr[$i]; for ...
- JS实现精确加减乘除
说明:项目中要使用 JS 实现自动计算的功能,进行一些浮点数运算时,计算结果却是一长串的值,这里提供一个解决方法,问题基本上可以解决. 具体代码如下: //加法函数 function accAdd(a ...
- 排名第一、第二的OCR软件
排名第一.第二的OCR软件 第一:ABBYY FineReader OCR世界排名第一,在俄罗斯获国际科技大奖奖超过卡巴斯基! 不仅仅只是文字识别,还能表格识别,版面还原,字体识别,文档结构 ...
- Android 基础知识点(持续更新)
一.AndroidManifest 每一个安卓工程都有AndroidManifest.xml的配置文件,在所有项目中该名称都不会变.该文件是Android工程的一个全局配置文件,所有在Android中 ...
- SectionIndexer中的getSectionForPosition()与getPositionForSection()
大家在做字母索引的时候常常会用到SectionIndexer这个类,里面有2个重要的方法 1. getSectionForPosition()通过该项的位置,获得所在分类组的索引号 2. getP ...
- reviewboard搭建
reviewboard的搭建 系统:fedora 19 内核版本:3.9.5-301.fc19.x86_64 步骤 命令 备注 安装mysql # yum -y install mysql mysql ...