BZOJ1053 [HAOI2007] 反素数ant
2016-01-21 21:59
465 查看
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1053
如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数。例如,整数1,2,4,6等都是反质数。
现在给定一个数N,你能求出不超过N的最大的反质数么?
看这个吧:这是一个百度文库链接
View Code
Description
对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数。例如,整数1,2,4,6等都是反质数。
现在给定一个数N,你能求出不超过N的最大的反质数么?
Input
一个数N(1<=N<=2,000,000,000)。Output
不超过N的最大的反质数。看这个吧:这是一个百度文库链接
#include <cstdio> #define rep(i,l,r) for(int i=l; i<=r; i++) using namespace std; typedef long long ll; const int p[] = {2,3,5,7,11,13,17,19,23,29}; ll n; int ans,num; void dfs(int x,ll now,int cnt,int last){ // 第几个质数,从开始搜索至今质数的乘积,质数个数,质数幂的次数 if (x == 9){ if (now > ans && cnt > num) ans = now, num = cnt; if (now <= ans && cnt >= num) ans = now, num = cnt; return; } int t = 1; rep(i,0,last){ dfs(x+1,now*t,cnt*(i+1),i); t *= p[x]; if (now * t > n) break; } } int main(){ scanf("%lld",&n); dfs(0,1,1,10); printf("%d\n",ans); return 0; }
View Code
相关文章推荐
- BZOJ3529: [Sdoi2014]数表
- leetcode 之Binary Tree Level Order Traversal II
- 依赖注入和反转控制的区别
- 关于Android 中 Options.inSampleSize怎么用
- 添加一个列到dataframe中
- Impression of《Bible》
- clock_t实际类型的查找流程
- C语言常用头文件总结
- python 学习笔记2
- 为什么Android上的一些SDK喜欢将数据库建在SD卡或外部存储
- hadoop:ls: `.': No such file or directory
- 一起talk C栗子吧(第一百零八回:C语言实例--线程创建与结束一)
- Android Fragment和Activity
- 包含min函数的栈
- poj 2318 TOYS
- 3、Java基础复习----集合 Collection、List
- android之ExpandableListView的使用
- 栈---顺序存储结构
- 蓝桥杯 算法训练 最大的算式(DP)
- test_mem_addr_align