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

ZOJ-2562 More Divisors

题意:给定一个n (1 <= n <= 10^16),求小于等于n的最大反素数。反素数(对于任何正整数x,起约数的个数记做g(x).例如g(1)=1,g(6)=4.

如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数.)。

思路:即求小于等于n的约数最多的数,因为一个数的因子数等于它所有素因子幂加1的乘积,要求最大的反素数,则素因子尽可能要少,幂尽可能要多,所以只对前15个素数所能组成的数进行遍历即可。

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1562

 

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 #define LL long long
10 
11 int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
12 LL n,Max,ans;
13 
14 void dfs(LL sum,LL num,int k,int t){
15     if(sum>Max) {Max=sum; ans=num;}
16     if(sum==Max&&num<ans) ans=num;
17     if(k>14) return ;
18     LL temp=num;
19     for(int i=1;i<=t;i++){
20         if(temp*prime[k]>n) break;
21         temp*=prime[k];
22         dfs(sum*(i+1),temp,k+1,i);
23     }    
24 }
25 
26 int main(){
27     
28 //    freopen("data.in","r",stdin);
29 //    freopen("data.out","w",stdout);
30     
31     while(scanf("%lld",&n)!=EOF){
32         Max=0;ans=n;
33         dfs(1,1,0,50);
34         printf("%lld\n",ans);    
35     }
36     return 0;
37 }
posted @ 2012-08-04 11:25  Hug_Sea  阅读(410)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3