zoj 2562 More Divisors

2014-11-24 11:40:46 · 作者: · 浏览: 1

题解:求出n以内的最大的反素数。

#include 
  
   
#include 
   
     using namespace std; typedef unsigned long long LL; LL p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; LL ans,sum; LL N; void dfs(LL i,LL x,LL n) { if(n>sum||(n==sum&&ans>x)) sum=n,ans=x; for(int k=1;k<=63;k++) { if(x*p[i]>N) break; dfs(i+1,x*=p[i],n*(k+1)); } } int main() { while(cin>>N) { ans=1e18; sum=1; dfs(0,1,1); cout<