Accept: 166 Submit: 760
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<stdio.h>
int prime[1000005]={0};
int prim()
{
prime[1]=prime[0]=1;
for(int i=1;i<=500000;++i) prime[i<<1]=2;
for(int i=3;i<1001;++i)
if(prime[i]==0)
{
prime[i]=i;
int k=i*i;
while(k<1000000)
{
if(prime[k]==0) prime[k]=i;
k+=i;
}
}
for(int i=2;i<1000000;i++)
if(prime[i]==0) prime[i]=i;
}
int main()
{
int n;
prim();
while(scanf("%d",&n)!=EOF)
{
int t=n;
int ans=1;
while(t>1)
{
int count=1;
int k=prime[t];
while(t%k==0)
{
t=t/k;
count++;
}
ans*=count;
}
printf("%d %d/n",ans-1,n/prime[n]);
}
return 0;
}