wjtwjtwjt @ 2017-10-04 20:35:13
直接放代码啦~~(也是醉了,,,第一次没过居然是因为数组没开够)
欧拉筛:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 20005
using namespace std ;
int cnt = 0 , vis[maxn*maxn] , prime[maxn] ;
void oula()
{
for(int i = 2 ; i <= maxn ; i ++ ){
if(!vis[i] ) prime[++cnt] = i ;
for(int j = 1 ; j <= cnt ; j ++ ){
vis[i*prime[j]] = 1 ;
if(i % prime[j] == 0 ) break ;
}
}
}
void output()
{
printf("%d\n",cnt) ;
printf("%d",prime[1]) ;
for(int i = 2 ; i <= cnt ; i ++ ) printf(",%d",prime[i]) ;
}
int main()
{
freopen("ouladb.out","w",stdout) ;
oula() ;
output() ;
return 0 ;
}
递归(借用打表技术):
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 10005
using namespace std ;
int p[maxn] = {2262,。。。(内容略,内容太长传不成啊。。)} ;
int ans[14] ;
void work(int n , int cnt , int start , int now ){
ans[cnt] = now ;
if(cnt == 3 ){
// printf("%d %d %d\n",ans[1],ans[2],ans[3]) ;
if(!n){
printf("%d %d %d\n",ans[1],ans[2],ans[3]) ;
exit(0) ;
}
return ;
}
for(int i = start ; i <= p[0] ; i ++ ){
if(p[i] > n ) break ;
work(n-p[i],cnt+1,i,p[i]) ;
}
}
int main()
{
int n ;
scanf("%d",&n) ;
for(int i = 1 ; i <= p[0] ; i ++ ) work(n-p[i],1,i,p[i]) ;
return 0 ;
}
by antiquality @ 2017-10-04 20:48:46
您可以交题解...
这样直接放代码对有些常看讨论的人来说不好
by CKnight @ 2017-10-25 19:13:56
20005*20005的bool会炸空间吧