SRM 400 DIV2 [500]
来源:互联网 发布:国外无法访问国内网络 编辑:程序博客网 时间:2024/05/03 17:55
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<cstdio>
using namespace std;
long long num;
bool is(int p,int q)
...{
long long temp=1;
for (int i=0;i!=q;++i)
temp*=(long long)p;
if (temp!=num) return false;
for (int i=2;i*i<=p;++i)
if (p%i==0) return false;
return true;
}
class StrongPrimePower...{
public:
vector <int> baseAndExponent(string n)
...{
vector<int> ans;
sscanf(n.c_str(),"%lld",&num);
double f=num;
for (int i=2;i!=65;++i)...{
int p=pow(f,(double)1/i)+0.5;
if (is(p,i))...{
ans.push_back(p);
ans.push_back(i);
return ans;
}
}
return ans;
}
};
Problem Statement
NOTE: This problem statement contains superscripts that may not display properly if viewed outside of the applet.
A number which can be represented as pq, where p is a prime number and q is an integer greater than 0, is called a prime power. If q is larger than 1, we call the number a strong prime power. You are given an integer n. If n is a strong prime power, return an vector <int> containing exactly two elements. The first element is p and the second element is q. If n is not a strong prime power, return an empty vector <int>.
Definition
Class: StrongPrimePower Method: baseAndExponent Parameters: string Returns: vector <int> Method signature: vector <int> baseAndExponent(string n) (be sure your method is public)Constraints
- n will contain digits ('0' - '9') only. - n will represent an integer between 2 and 10^18, inclusive. - n will have no leading zeros.Examples
0)"27"
Returns: {3, 3 }27 = 33. This is a strong prime power. 1)
"10"
Returns: { }10 = 2 * 5. This is not a strong prime power. 2)
"7"
Returns: { }A prime number is not a strong prime power. 3)
"1296"
Returns: { }4)
"576460752303423488"
Returns: {2, 59 }5)
"999999874000003969"
Returns: {999999937, 2 }
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
- SRM 400 DIV2 [500]
- SRM 400 DIV2 [250]
- TC SRM 400 DIV2
- SRM 397 DIV2 [500]
- SRM 421Div2 500
- SRM 457 Div2 500
- SRM 586 DIV2 500
- SRM 597 DIV2 500
- TC SRM div2 500
- Topcoder srm div2 500
- srm 535 div2 250&500
- topcoder SRM 500 div2 level3
- SRM 499 DIV2 500pt
- Topcoder SRM 582 DIV2 500
- topcoder SRM 548 DIV2 500
- SRM 599 div2 250 500
- SRM 606 div2 500 EllysNumberGuessing
- SRM 608 div2 500 MysticAndCandiesEasy
- 我人生的IT之旅从今晚开始
- javascript 事件处理 IE和标准dom 的差别
- java简易成绩管理程序
- SRM 400 DIV2 [250]
- ADS ADS1.2 内存字节对齐
- SRM 400 DIV2 [500]
- Javascript attachEvent传递参数的办法
- visual c++学习笔记socket编程
- TinyXML 解析中文XML
- SRM 397 DIV2 [1000]
- GVIM设置文件编码
- 家乐福事件之我见(转帖)
- 2008.05.01
- 8259A的工作方式