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 ...
随机推荐
- CSS伪类对象before和after的用法
一直感觉这两个伪类对象不是很重要,并且IE对它两兄弟并不支持,所以也没有怎么静下心来研究,只有在清楚浮动clearfix的时候会用到哈,其他都很 少用!不过最近在研究css3的时候觉得它两个的搭配不仅 ...
- session 保存在指定的数据表,cookie设置
首先建立数据表,可在ThinkPHP/Extend/Driver/Session/SessionDb.class.php中copy代码 在配置文件中配置: 'SESSION_TYPE' => ' ...
- C#基础(二)——C#中的构造函数
构造函数主要是用来创建对象时为对象赋初值来初始化对象.总与new运算符一起使用在创建对象的语句中 .A a=new A(); 构造函数具有和类一样的名称:但它是一个函数具有函数的所有特性,同一个类里面 ...
- Invoke()方法的使用
在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法是错误的做法,Invoke 和 BeginInvoke 就是为了解决这个问题而出现的,使你在多线程中安全的更新界 ...
- winform模拟鼠标按键
今天朋友说被他们公司的学习网站恶心到了,下班后要他看学习资料,看完点下一页,而且一页必须停留多少时间才能点击下一页,想不看都不行,于是晚上我突发奇想要给他做一个模拟鼠标按键的程序,可以让鼠标定时间隔触 ...
- 转载:Source Insight查看ARM汇编源程序 && 高亮显示程序 && Source Insight打开project窗口出错
(1)Source Insight查看ARM汇编源程序.做ARM嵌入式开发时,有时得整汇编代码,但在SIS里建立PROJECT并ADD TREE的时候,根据默认设置并不会把该TREE里面所有汇编文件都 ...
- SDUT 1305 查找基因序列问题 dp
题目: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1305 这个题就是一个类似公共子串的dp ...
- 实现CodeFirst自动数据迁移无需命令
本主题假设您掌握了实体框架中 Code First 迁移的基本知识. 借助自动迁移功能,您无需对您所做的每一个更改都在程序包管理器控制台中运行Update-Database 命令. 启用迁移 只需执行 ...
- C# net部署图片分布式存储服务器的小案例
如果web服务用户多了,访问多了,用户上传的图片,文件等内容放在一块,想必服务器是承受不住的,这个时候,我们就需要考虑分布式存储的方法了. 如图所示:一个web服务器拖2个图片服务器 如何做到用户上传 ...
- bzoj 1200: [HNOI2005]木梳 DP
1200: [HNOI2005]木梳 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 266 Solved: 125[Submit][Status] ...