wzhhhhh @ 2017-11-05 18:19:05
#include<cstdio>
#include<cmath>
using namespace std;
#define maxn 20010
int is_prime(int n)
{
int x;
x=floor(sqrt(n)+0.5);
if(n==2)return 1;
for(int i=2;i<=x;i++)
if(n%i==0) return 0;
return 1;
}
int main()
{
int prime[10000],m=1,i,j,k,n,a,b,c;
for(i=2;i<=maxn;i++)
{
bool tmp;
tmp=is_prime(i);
if(tmp==1)
{
prime[m]=i;
m++;
}
}
scanf("%d",&n);
for(i=1;prime[i]<n;i++)
{
for(j=1;prime[j]<n;j++)
{
for(k=1;prime[k]<n;k++)
{
if(prime[i]+prime[j]+prime[k]==n)
{a=prime[i];b=prime[j];c=prime[k];break;}
}
}
}
printf("%d %d %d\n",c,b,a);
return 0;
}
by RoderickQiu @ 2018-02-25 11:00:21
打表出奇迹
by sunzhen @ 2019-02-02 19:42:10
for(int i=2;i<n;(i%2==0)?i++:i+=2)
{
for(int j=2;j<n;(j%2==0)?j++:j+=2)
{
for(int k=2;k<n;(k%2==0)?k++:k+=2)
改成这样,一次前进2,就不会t了
by sunzhen @ 2019-02-02 19:48:41
for(int j=2;j<n;(j%2==0)?j++:j+=2)
{
for(int k=2;k<n;(k%2==0)?k++:k+=2)
{
if(isprime(n-k-j,j,k))
{
或者这样,直接少一组for循环