FZU1607 Greedy division(逆向思维)

D - Greedy division
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit  Status

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.


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
int a[1000001]={0};
void init()
{
    for(int i=1;i<1000001;i++)
    {
        for(int j=1;i*j<1000001;j++)
        {
            a[i*j]++;
        }
    }
}
int main(){
    int n;
    init();
    while(scanf("%d",&n)!=-1)
    {
        if(a[n]==2)
        {
            printf("1 1\n");
            continue;
        }
        int flag;
        for(int i=2;;i++)
        {
            if(n%i==0)
            {
                flag=i;
                break;
            }
        }
        printf("%d %d\n",a[n]-1,n/flag);
    }
    return 0;
}

你可能感兴趣的:(FZU1607 Greedy division(逆向思维))