链接:

https://www.acwing.com/problem/content/200/

题意:

对于任何正整数x,其约数的个数记作g(x),例如g(1)=1、g(6)=4。

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

例如,整数1,2,4,6等都是反素数。

现在给定一个数N,请求出不超过N的最大的反素数。

思路:

考虑前11个素数的乘积大于2e9, 可以对n用前10个质数进行质数分解.

考虑2^31 > 2e9. 然后限制一下范围, DFS跑一遍.

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL; const LL MAXV = 2e9;
int Pri[20] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
int Cnt[20];
LL cnt, res, n; LL Pow(LL a, int b)
{
LL tmp = 1;
while (b > 0)
{
if (b&1)
tmp *= a;
a *= a;
b >>= 1;
}
return tmp;
} void Dfs(int step, LL val)
{
// cout << step << ' ' << val << endl;
if (step > 10)
{
LL tmp = 1;
for (int i = 1;i <= 10;i++)
tmp *= (Cnt[i]+1);
if (tmp > cnt)
{
cnt = tmp;
res = val;
}
else if (tmp == cnt && val < res)
{
cnt = tmp;
res = val;
}
return;
}
for (int i = 0;i <= 30;i++)
{
if (val*Pow(Pri[step], i) > n)
break;
Cnt[step] = i;
Dfs(step+1, val*Pow(Pri[step], i));
}
} int main()
{
memset(Cnt, 0, sizeof(Cnt));
scanf("%lld", &n);
if (n == 1)
{
puts("1");
return 0;
}
Dfs(1, 1);
printf("%lld\n", res); return 0;
}

最新文章

  1. ASP.NET MVC Html.BeginForm 设置 timeout
  2. MySQL 游标
  3. HashPasswordForStoringInConfigFile中的Md5算法并非常用的Md5算法
  4. c语言是如何实现泛型链表
  5. Linux下网络故障诊断
  6. WP 类似扑克牌布局控件和类似扑克卡片控件
  7. python 发送邮件例子
  8. 框架应用 : Spring MVC - 开发详述
  9. shell编程--流程控制for,do-while,if-then,break,continue,case等
  10. C# 实体转为json字符串
  11. codeforces_Codeforces Round #541 (Div. 2)_abc
  12. 【译】Optaplanner开发手册本地化: (0) - 前言及概念
  13. JDK和CGLIB动态代理区别
  14. Good Bye 2018
  15. Linux基础命令---lp打印文件
  16. js md5 中文
  17. 【未完待续】API接口
  18. hadoop中 bin/hadoop fs -ls ls: `.&#39;: No such file or directory问题
  19. javascript进阶笔记(3)
  20. 在Mac上搭建ReactNative开发环境

热门文章

  1. quartus ii 粗略使用教程
  2. SQLServer启动和关闭bat脚本
  3. # [Poj 3107] Godfather 链式前向星+树的重心
  4. Python学习8——魔法方法、特性和迭代器
  5. 【hash】A Horrible Poem
  6. luogu P2423 [HEOI2012]朋友圈 (最大团)
  7. Java 反射理解(二)-- 动态加载类
  8. redis 学习(17) -- RDB
  9. (转载)项目中表、类、包、JSP命名规范
  10. O038、Shelve Instance 操作详解