| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
第一次贴代码,已AC,题意请看其他帖子#include<stdio.h>
#include<sstream>
#include<string.h>
using namespace std;
typedef long long LL;
const int maxn = 10005;
char s[maxn];
int num[100],factor[100],cnt;
//快速幂
LL pow(LL a,int b){
LL ret = 1;
while(b){
if(b&1)ret*=a;
a*=a;
b>>=1;
}
return ret;
}
//素因子分解
void get_factor(LL ans){
cnt=0;
int i=2;
memset(num,0,sizeof(num));
while(ans>=i){
while(ans%i==0){
ans/=i;
num[cnt]++;
}
if(num[cnt]!=0)factor[cnt++] = i;
++i;
}
}
int main(){
while(1){
gets(s);
if(s[0]=='0')break;
char a[100],b[100];
int c,d;
stringstream ss(s);
LL ans = 1;
while(ss>>a){
sscanf(a,"%d",&c);
ss>>b;
sscanf(b,"%d",&d);
ans *= pow(c,d);
}
ans-=1;
get_factor(ans);
for(int i=cnt-1;i>=0;--i){
printf("%d %d%c",factor[i],num[i],i==0?'\n':' ');
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator