2014-10-01 14:32:29
反素数:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数·
刷题时,无意看到一个人求反素数的方法,感觉不错。(注意,只是单次求最大的小于等于n的反素数!)
1 /************************************************************************* 2 > File Name: atp.cpp 3 > Author: Nature 4 > Mail: 564374850@qq.com 5 > Created Time: Wed 01 Oct 2014 02:27:01 PM CST 6 ************************************************************************/ 7 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <cmath> 12 #include <vector> 13 #include <queue> 14 #include <iostream> 15 #include <algorithm> 16 using namespace std; 17 #define lpos (pos << 1) 18 #define rpos (pos << 1|1) 19 #define getmid(l,r) (l + (r - l) / 2) 20 typedef long long ll; 21 const int INF = 1 << 29; 22 const int maxn = 500010; 23 24 int n,p[maxn],o[maxn]; 25 26 int main(){ 27 scanf("%d",&n); 28 for(int i = 1;i <= n;i ++){ 29 p[i] = 0; 30 o[i] = 0; 31 } 32 for(int i = 1;i <= n;i ++){ 33 for(int j = i;j <= n;j += i){ 34 o[j]++; 35 } 36 } 37 int maxz = 0; 38 int key = 1; 39 for(int i = 2;i <= n;i ++){ 40 if(maxz < o[i]){ 41 maxz = o[i]; 42 key = i; 43 } 44 } 45 printf("%d\n",key); 46 return 0; 47 }