首页 > 其他 > 详细

fzuoj1607Greedy division

时间:2014-07-06 00:44:58      阅读:458      评论:0      收藏:0      [点我收藏+]

题目链接:

点我点我

题目:

bubuko.com,布布扣 Problem 1607 Greedy division

Accept: 436    Submit: 1590
Time Limit: 1000 mSec    Memory Limit : 32768 KB

bubuko.com,布布扣 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?

bubuko.com,布布扣 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.

bubuko.com,布布扣 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.

bubuko.com,布布扣 Sample Input

568

bubuko.com,布布扣 Sample Output

1 13 33 4

bubuko.com,布布扣 Hint

There are huge tests, so you should refine your algorithm.

bubuko.com,布布扣 Source

FOJ月赛-2008年5月

思路:

这个题目首先预处理,其实这个题目就是在求有多少个因数,所以可以用素数打表的思路,因为每次扫描到的j,一定是i的倍数,故a[j]++,例如是24,则i到2,3,4,6,8,12,24时都会加一次。。。然后就是如果是素数,则直接输出1和1.相当于一种优化吧。。

代码为:

#include<cstdio>
#include<cstring>
const int maxn=1000000+10;
int a[maxn];
int main()
{
    int n,i;
    memset(a,0,sizeof(a));
    for(int i=2;i<=maxn;i++)
        for(int j=i;j<=maxn;j=j+i)
            a[j]++;
    while(~scanf("%d",&n))
    {
        if(a[n]==1)
            printf("%d %d\n",1,1);
        else
            {
                for(i=2;i<=maxn/2;i++)
                    if(n%i==0)
                     break;
                printf("%d %d\n",a[n],n/i);
            }

    }
    return 0;
}


fzuoj1607Greedy division,布布扣,bubuko.com

fzuoj1607Greedy division

原文:http://blog.csdn.net/u014303647/article/details/36736549

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!