Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

第一次贴代码,已AC,题意请看其他帖子

Posted by 920394589 at 2017-08-17 14:27:06 on Problem 1365
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator