//懒得解释
#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的更多相关文章

随机推荐

  1. UVa 101 (模拟) The Blocks Problem

    题意: 有n个木块及n个木块堆,初始状态是第i个木块在第i个木块堆上.对应有四种操作,然后输出最终状态. 分析: 用一个vector<int>模拟一个木块堆,进行相应操作即可. #incl ...

  2. [POJ 2420] A Star not a Tree?

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4058   Accepted: 200 ...

  3. SQL LEFT JOIN 关键字

    SQL LEFT JOIN 关键字 LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行. LEFT JOIN 关键 ...

  4. (4)java方法区

    java方法区[名词解析]        --->和java堆一样,方法区是一块所有线程共享的内存区域.        --->保存系统的类信息,比如,类的字段,方法,常量池等.      ...

  5. 设计模式Day01

    一.工厂模式 1.工厂模式的关键点就是如何描述好这两个角色之间的关系,分为四种情况: (1)单一产品系,工厂生产一种类型的产品: (2)多产品系,特征相同.工厂生产多种类型的产品: (3)多产品系,部 ...

  6. JVM的GC机制及JVM的调优方法

    内存管理和垃圾回收是JVM非常关键的点,对Java性能的剖析而言,了解内存管理和垃圾回收的基本策略非常重要. 1.在程序运行过程当中,会创建大量的对象,这些对象,大部分是短周期的对象,小部分是长周期的 ...

  7. 【原】Storm 消息处理保障机制

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  8. 8.3 MPI

    MPI 模型 如图MPI的各个运算节点是分布式的.每一个节点可以视为是一个“Thread”,但这里的不同之处在于这些节点没有所谓的共享内存,或者说Global Memory.所以,在后面也会看到,一般 ...

  9. sql-逻辑循环while if

    --计算1-100的和 declare @int int=1; declare @total int=0; while(@int<=100) begin set @total=@total+@i ...

  10. 细谈Linux和windows差异之图形化用户接口、命令行接口

    相信来看本博文的朋友,肯定是已经玩过linux好段时间了,才能深刻理解我此番话语. 这是在Windows下的命令行接口 这是windows下的用户接口 就是它,explorer.ext,可以去尝试.把 ...