foj 1607

牢骚:刚刚考完线代,被虐了,不爽,洗了个澡回来切道题吧...

Problem 1607 Greedy division

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

5
6
8

Sample Output

1 1
3 3
3 4

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;
}    
               

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值