POJ_1365_Prime_Land
//懒得解释
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
#define Max 110000
#define Size 100000
#define Type int
bool isPrime[Max];
Type primeTable[Max];
Type expCount[Max]; void primeRadiation(const Type& size){
memset(isPrime,true,sizeof(isPrime));
isPrime[1]=false;
for(Type i=4;i<=size;i+=2) isPrime[i]=false;
for(Type i=3;i<=sqrt(size);++i){
if(isPrime[i]==true){
const Type step=2*i;
for(Type j=i*i;j<=size;j+=step) isPrime[j]=false;
}
}
} int setPrimeTable(const Type& size){
memset(primeTable,0,sizeof(primeTable));
int index=0;
for(int i=1;i<=size;++i){
if(isPrime[i]==true){
index++;
primeTable[index]=i;
}
}
return index;
} void countExp(Type num){
memset(expCount,0,sizeof(expCount));
Type index=1;
while(num!=1){
if(num%primeTable[index]==0){
num/=primeTable[index];
expCount[index]++;
}
else{
index++;
}
}
} int main(){
char c;
Type base;
Type exp;
primeRadiation(Size);
Type t=setPrimeTable(Size);
while(1){
Type ans=1;
cin>>base;
if(base==0) break;
cin>>exp;
ans*=pow(base,exp);
while(1){
c=getchar();
if(c=='\n') break;
cin>>base;
cin>>exp;
ans*=pow(base,exp);
}
Type temp=ans-1;
countExp(temp);
for(Type i=temp;i>=1;--i){
if(expCount[i]!=0) cout<<primeTable[i]<<" "<<expCount[i]<<" ";
}
cout<<endl;
}
return 0;
}
POJ_1365_Prime_Land的更多相关文章
随机推荐
- Codeforces Round #221 (Div. 2) Lever I.O.U.
这场cf 做的很差,,第一题犯了一个很低级的错误..把i写成了J.... 第二题 想的太复杂了...其实我们只需要 考虑每个人自己的负债情况就行了,就是假设每个人把别人 欠他的钱,拿过来还给别人..这 ...
- 函数buf_page_get
/**************************************************************//** NOTE! The following macros shoul ...
- Java内省
什么是内省? Java语言对bean类属性.事件的一种缺省处理方法,例如类A中有属性name,那我们可以通过getName,setName来得到其值或者设置新的值. 什么是JavaBean? Java ...
- C# DateDiff与DateAdd
原文地址:http://www.wlm.so/Article/Detail/lmb49q5hxpqyi00000 刚刚在百度上搜C#里面的DateDiff,一看吓一跳,C#没有这个函数. 还有各种自定 ...
- vijos 1563 疯狂的方格取数
P1653疯狂的方格取数 Accepted 标签:天才的talent[显示标签] 背景 Due to the talent of talent123,当talent123做完NOIP考了两次的二取 ...
- 如何在一个frame中调用另一个frame中的javascript函数
1.htm <script language="javascript">function test(){alert("测试")}</scrip ...
- 【转】Android异步消息处理机制完全解析,带你从源码的角度彻底理解
原文网址:http://blog.csdn.net/guolin_blog/article/details/9991569 转载请注明出处:http://blog.csdn.net/guolin_bl ...
- 软件测试模型汇总-V模型,W模型,X模型,H模型
V模型 在软件测试方面,V模型是最广为人知的模型,尽管很多富有实际经验的测试人员还是不太熟悉V模型,或者其它的模型.V模型已存在了很长时间,和瀑布开发模型有着一些共同的特性,由此也和瀑布模型一样地受到 ...
- 浅谈reverse_iterator的base()函数
非原创,原文链接:http://blog.csdn.net/shuchao/article/details/3705252 调用reverse_iterator的base成员函数可以产生"对 ...
- HW5.36
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...