Accept: 339 Submit: 1301
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Oaiei has inherited a large sum of wealth recently; this treasure has n pieces of golden coins. Unfortunately, oaiei can not own this wealth alone, and he must divide this wealth into m parts (m>1). He can only get one of the m parts and the m parts have equal coins. Oaiei is not happy for only getting one part of the wealth. He would like to know there are how many ways he can divide the wealth into m parts and he wants as many golden coins as possible. This is your question, can you help him?
Input
There are multiply tests, and that will be 500000. For each test, the first line is a positive integer N(2 <= N <= 1000000), N indicates the total number of golden coins in the wealth.
Output
For each test, you should output two integer X and Y, X is the number of ways he can divide the wealth into m parts where m is large than one, Y is the number of golden coins that he can get from the wealth.
Sample Input
Sample Output
Hint
There are huge tests, so you should refine your algorithm.
Source
FOJ月赛-2008年5月#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 1005
bool x[maxn];
int prime[maxn],m=0;
void Init()
{
int i,tmp;
memset(x,false,sizeof(x));
x[0]=x[1]=true;
for(i=2;i<maxn;i++)
{
if(!x[i])
{
prime[++m]=i;
tmp=i*2;
while(tmp<maxn)
{
x[tmp]=true;
tmp+=i;
}
}
}
}
int main()
{
Init();
int n,i,k,ans,num,tmp;
while(~scanf("%d",&n))
{
ans=1;
num=tmp=n;
for(i=1;i<=m&&prime[i]*prime[i]<=n;i++)
{
if(n&&n%prime[i]==0)
{
if(prime[i]<num)
num=prime[i];
k=0;
while(n&&n%prime[i]==0)
{
k++;
n/=prime[i];
}
ans*=(k+1);
}
}
if(n>1)
ans*=2;
printf("%d %d\n",ans-1,tmp/num);
}
return 0;
}