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的更多相关文章
随机推荐
- 基于邻接矩阵的深度优先搜索(DFS)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2107&cid=1186 #include<stdio.h> #incl ...
- 使用Zxing实现扫二维码描
1.集成Zxing.bar 2.复制代码到项目中 3.修改 MipacActivityCapture.java 的扫描结果方法 handleDecode() /** * 处理扫描结果,实现活动页面跳 ...
- amoeba-mysql配置安装(收集整理)
本文收集整理自: Amoeba搞定mysql主从读写分离 http://blog.chinaunix.net/uid-20639775-id-154600.html Amoeba非常好用的mysql集 ...
- Java [leetcode 22]Generate Parentheses
题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed par ...
- Can not perform pod install under el capitan (15A279b)
这个问题在stackoverflow上面有过讨论: Can not perform pod install under el capitan (15A279b) 被采纳的答案为:sudo gem in ...
- SSL 通信原理及Tomcat SSL 配置
SSL 通信原理及Tomcat SSL 双向配置 目录1 参考资料 .................................................................. ...
- yahoo 交易数据
yahoo提供国内和国外股市每天的交易数据资料,这可谓一大幸事啊.http://table.finance.yahoo.com/table.csv?s=ibm&d=6&e=22& ...
- 统计计算与R语言的资料汇总(截止2016年12月)
本文在Creative Commons许可证下发布. 在fedora Linux上断断续续使用R语言过了9年后,发现R语言在国内用的人逐渐多了起来.由于工作原因,直到今年暑假一个赴京工作的机会与一位统 ...
- 2015北京网络赛B题 Mission Impossible 6
借用大牛的一张图片:模拟 #include<cstdio> #include<cmath> #include<cstring> #include<algori ...
- gimp之旅
随着大学生活的告一段落,新的征途已经开始了.鉴于本人如此喜欢旅游,如此喜欢拍照,如此喜欢处理图片,所以打算在照片处理上下点功夫.总所周知,图像处理软件大牛级的就属windows下的photoshop以 ...