标签:rip com 题目 opened output 一个 数据 ide sed
1 #include<iostream> 2 #include<cstdlib> 3 #include<cstdio> 4 #include<cstring> 5 #include<queue> 6 #include<algorithm> 7 #include<cmath> 8 #include<map> 9 #define N 50005 10 using namespace std; 11 long long sq,n,ss[N],zz,ans=4294967296; 12 bool fss[N]; 13 bool pri(long long x) 14 { 15 for(int i=2;i<=sqrt(x);i++) 16 if(x%i==0)return 0; 17 return 1; 18 } 19 void dfs(long long sum,long long wz,long long now) 20 { 21 if(sum>ans)return; 22 if(now==1) 23 { 24 ans=min(ans,sum); 25 return; 26 } 27 if(now>sq&&pri(now+1))ans=min(ans,(now+1)*sum); 28 for(int i=wz;i<=zz&&ss[i]-1<=sq&&ss[i]-1<=now;i++) 29 { 30 if(now%(ss[i]-1)==0) 31 { 32 int x=now/(ss[i]-1),y=sum*ss[i]; 33 dfs(y,i+1,x); 34 while(x%ss[i]==0) 35 { 36 x/=ss[i],y*=ss[i]; 37 dfs(y,i+1,x); 38 } 39 } 40 } 41 } 42 int main() 43 { 44 scanf("%lld",&n); 45 sq=sqrt(n); 46 for(int i=2;i<=sqrt(n);i++) 47 { 48 if(!fss[i]) 49 { 50 zz++; 51 ss[zz]=i; 52 } 53 for(int j=1;j<=zz&&i*ss[j]<N;j++) 54 { 55 fss[i*ss[j]]=1; 56 if(i%ss[j]==0)break; 57 } 58 } 59 dfs(1,1,n); 60 if(ans<2147483648ll) 61 printf("%lld\n",ans); 62 else printf("-1\n"); 63 return 0; 64 }
标签:rip com 题目 opened output 一个 数据 ide sed
原文地址:http://www.cnblogs.com/liutianrui/p/7536777.html