FOJ-1607 Greedy division

题意:给定一个n,将n平均分成m份,问有几种方法,每种方法中找出最大的数。

思路:就是求n的因子数、先将每个数求出最小素因子、再将n的所有素因子数加1相乘。

小结论:求一个数的所有因子数、先分解、n=(a^x)*(b^y)*(c^z),(a、b、c均为素数),因子数=(x+1)*(y+1)*(z+1)。

题目链接:http://acm.fzu.edu.cn/problem.php?pid=1607

 

View Code
 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iostream>
 8 using namespace std;
 9 const int N=1000010;
10 
11 int MIN[N];
12 int n;
13 
14 int main(){
15     
16 //    freopen("data.in","r",stdin);
17 //    freopen("data.out","w",stdout);
18     
19     memset(MIN,0,sizeof(MIN));
20     for(int i=2;i<N;i+=2) MIN[i]=2;
21     for(int i=3;i<N;i++){
22         if(MIN[i]==0){
23             MIN[i]=i;
24             if(i>sqrt(N*1.0)) continue;
25             for(int j=i*i;j<N;j+=i)
26                 if(MIN[j]==0) MIN[j]=i;
27         }
28     }
29     while(scanf("%d",&n)!=EOF){
30         int t=n;
31         int ans=1;
32         while(t>1){
33             int cnt=1;
34             int k=MIN[t];
35             while(t%k==0){
36                 t/=k;
37                 cnt++;
38             }
39             ans*=cnt;
40         }
41         printf("%d %d\n",ans-1,n/MIN[n]);
42     }
43     return 0;
44 }

转载于:https://www.cnblogs.com/Hug-Sea/articles/2617712.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值