反素数入门 zoj 2562 and codefore
来源:互联网 发布:ubuntu.vmx损坏 编辑:程序博客网 时间:2024/06/05 18:07
学习资料来源传送们
反素数的定义:对于任何正整数,其约数个数记为,例如,如果某个正整数满足:对任意的正整
数,都有,那么称为反素数定义理解:素数的约数只有两个 1 和 本身,而反素数的约数是尽可能多,比这个数小到正数的约数都要多
在ACM竞赛中,最常见的问题如下:
(1)给定一个数,求一个最小的正整数,使得的约数个数为
(2)求出中约数个数最多的这个数
题目:
http://codeforces.com/problemset/problem/27/E
题意:
给出一个数 n ,求一个最小的数,这个数的约数个数恰好为 n 个
题解:
对于一颗质因子分解的树进行搜索
例如:
,以每一个为树的一层建立搜索树,深度为
以为例进行说明,建树如下:
/************************************************************************* > File Name: main.cpp > Author: ma6174 > Mail: ma6174@163.com > Created Time: 2017年11月21日 星期二 00时24分07秒 ************************************************************************/#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;#define ULL unsigned long long#define INF ~0ULLint n;ULL ans;int p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};void dfs(int dept,ULL temp,int num){if(num>n) return ;if(num==n&&ans>temp) ans=temp;for(int i=1;i<64;i++){if(ans/p[dept]<temp) break;dfs(dept+1,temp*=p[dept],num*(i+1));}}int main(){freopen("in.txt","r",stdin);while(cin>>n){ans=INF;dfs(0,1,1);cout<<ans<<endl;}return 0;}
zoj2562
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1562
题意:
给出n,求1~n中约数个数最多的数字
题解:
修改上叙代码
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;#define ULL unsigned long long#define INF ~0ULLint best;ULL n,ans;int p[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};void dfs(int dept,ULL temp,int num){if(dept>=16) return;if(num>best){best=num;ans=temp;}if(num==best&&ans>temp) ans=temp;for(int i=1;i<64;i++){if(n/p[dept]<temp) break;dfs(dept+1,temp*=p[dept],num*(i+1));}}int main(){freopen("in.txt","r",stdin);while(cin>>n){ans=INF;best=0;dfs(0,1,1);cout<<ans<<endl;}return 0;}
阅读全文
0 0
- 反素数入门 zoj 2562 and codefore
- zoj 2562(反素数)
- ZOJ 2562 反素数
- zoj 2562 More Divisors(反素数)
- Zoj 2562 More Divisors (反素数)
- zoj 2562 More Divisors(反素数)
- ZOJ 2562 HDU 4228 反素数
- ZOJ 2562 More Divisors 反素数 DFS
- ZOJ More Divisors 2562 (反素数)
- ZOJ 2562 More Divisors 解题报告(反素数)
- ZOJ Problem Set - 2562 More Divisors 反素数
- zju 2562 反素数
- 反素数应用 ZOJ 2562 More Divisors + Timus OJ 1748. The Most Complex Number
- zoj 1562 反素数 附上个人对反素数性质的证明
- 反素数
- 反素数
- 反素数
- 反素数
- 从开发框架提高开发效率说起
- opencv3计算机视觉Python语言实现(原书第二版)第三章3.6节缺少BGRPortraCurveFilter()函数
- bootstrapValidator 重新手动触发验证
- hadoop(3)map reduce
- RBTree
- 反素数入门 zoj 2562 and codefore
- altium designer 方便实用的技巧
- eclipse中git插件的使用(项目提交到码云)
- 慌不择路地浅谈一下iOS的协议protocol
- Hibernate学习之一对一映射
- 翻译 PyMongo 文档
- mybatis和hibernate的区别
- Ueditor编辑器修改字体和字号?
- 软件测试自学指南---从入门到精通