牢骚:刚刚考完线代,被虐了,不爽,洗了个澡回来切道题吧...
Accept: 387 Submit: 1429
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.
题目大意:有N个金币,等分成m份(m〉1),问有几种分法,m最小时每份有多少金币。
解题思路:求出N的因子个数就行了,具体来说就是求出N的质因子,并记录每个质因子的个数ci,那么N的因子个数就是(c1+1)(c2+1)...(cn+1),由于查询次数为5*10^5,所以采用离线算法,预先打出表来。使用scanf,printf。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n[1000005];
int l[1000005];
void work()
{
memset(n,0,sizeof(n));
n[1]=1;
l[1]=1;
int i,j,t,k;
for(i=2;i<1000001;++i)
{
if(n[i]==0)
{
// n[i]=2,l[i]=i;
for(j=i;j<1000001;j+=i)
{
t=j;
k=0;
while(t%i==0)
{
k++;
t/=i;
}
if(n[j]==0)
{
n[j]=k+1;
l[j]=i;
}
else
n[j]*=(k+1);
}
}
}
}
int main()
{
int N;
work();
while(scanf("%d",&N)!=EOF)
{
// cout<<n[N]-1<<" "<<N/l[N]<<endl;
printf("%d %d\n",n[N]-1,N/l[N]);
}
return 0;
}
1818

被折叠的 条评论
为什么被折叠?



