反素数入门 zoj 2562 and codefore
2017-11-20 16:52
225 查看
学习资料来源传送们
反素数的定义:对于任何正整数
,其约数个数记为
,例如
,如果某个正整数
满足:对任意的正整
数
,都有
,那么称
为反素数
定义理解:素数的约数只有两个 1 和 本身,而反素数的约数是尽可能多,比这个数小到正数的约数都要多
在ACM竞赛中,最常见的问题如下:
(1)给定一个数
,求一个最小的正整数
,使得
的约数个数为
(2)求出
中约数个数最多的这个数
题目:
http://codeforces.com/problemset/problem/27/E
题意:
给出一个数 n ,求一个最小的数,这个数的约数个数恰好为 n 个
题解:
对于一颗质因子分解的树进行搜索
例如:
,以每一个
为树的一层建立搜索树,深度为
以
为例进行说明,建树如下:
zoj2562
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1562
题意:
给出n,求1~n中约数个数最多的数字
题解:
修改上叙代码
反素数的定义:对于任何正整数
,其约数个数记为
,例如
,如果某个正整数
满足:对任意的正整
数
,都有
,那么称
为反素数
定义理解:素数的约数只有两个 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 ~0ULL int 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 ~0ULL int 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; }
相关文章推荐
- Codefores Round #263 (div2) B. Appleman and Card Game
- 【CodeFores 798B】 Mike and strings(模拟+string)
- Codefores 785E Anton and Permutation(分块)
- Codeforecs 785C Anton and Fairy Tale 数学+二分
- codeforecs--D. Tanya and Password(输出欧拉路径)
- Codefores Round #419 (Div.2) - C. Karen and Game(暴力模拟)
- codeforcces Karen and Game 思维
- (zz)Good and Bad PHP Code
- Question about thread exit code and thread handle value
- codeforces Karen and Coffee (区间贡献 思维)
- best strategies for implementation of equals() and hashcode() in your persistent classes
- Codeforces Round 389 Div.2 B. Santa Claus and Keyboard Check(模拟)
- Codechef Sam and Sequences(单调队列)
- Dima and Salad CodeForces - 366C 背包DP
- 742 B - Arpa’s obvious problem and Mehrdad’s terrible solution codeforces
- 好文推荐:Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- codeforces GoodBye2015 D.New Year and Ancient Prophecy (dp+lcp+树状数组)
- Codeforces Round #404 (Div. 2) D. Anton and School - 2 前缀的后缀、 范德蒙恒等式、容斥
- Educational Codeforces Round 27 B. Luba And The Ticket(模拟)