Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607

 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

568

 Sample Output

1 13 33 4

 Hint

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

 Source

FOJ月赛-2008年5月

[cpp]  view plain copy
  1. #include<cstdio>  
  2. #include<iostream>  
  3. #include<algorithm>  
  4. #include<cmath>  
  5. #include<memory.h>  
  6. using namespace std;  
  7. int prime[1000005];  
  8. int minp[1000005];  
  9. int n, m, ans, k, choices;  
  10. int main(){  
  11.   
  12.     //freopen("in.txt", "r", stdin);  
  13.     /*int d = sqrt(1000005); 
  14.     memset(prime, 0, sizeof(prime)); 
  15.     for(int i=2;i<=d;++i){ 
  16.         if(!prime[i]){ 
  17.             prime[i] = 1; 
  18.             minp[i] = i; 
  19.             for(int j=i*2;j<=1000000;j+=i){ 
  20.                 if(!prime[j]){ 
  21.                     prime[j] = 2; 
  22.                     minp[j] = i; 
  23.                 } 
  24.  
  25.             } 
  26.         } 
  27.     }*/  
  28.     memset(prime,0,sizeof(prime));  
  29.     int ddd=sqrt(1000000.0)+1;  
  30.     for(int i=2;i<=1000000;i++)  
  31.     {  
  32.         if(prime[i])continue;  
  33.         minp[i]=i;  
  34.         if(i>ddd)continue;  
  35.         for(int j=i*2;j<=1000000;j+=i)  
  36.             if(prime[j]==0)  
  37.                 prime[j]=1,minp[j]=i;  
  38.     }  
  39.   
  40.   
  41.     while(scanf("%d", &n)!=EOF){  
  42.         m = n;  
  43.         ans = 1;  
  44.   
  45.         while(n>1){  
  46.             k = minp[n];  
  47.             choices = 1;  
  48.             while(n%k==0){  
  49.                 choices++;  
  50.                 n /= k;  
  51.             }  
  52.             ans *= choices;  
  53.         }  
  54.         printf("%d %d\n", ans-1, m/minp[m]);  
  55.     }  
  56.   
  57.     //fclose(stdin);  
  58.   
  59. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值