• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

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 }
posted @ 2012-08-01 09:20  Hug_Sea  阅读(144)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3