gdjcwsk @ 2019-09-23 15:31:05
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
bool p(ll a)
{
ll b=sqrt(a);
for(int i=2;i<=b;i++)
{
if(a%i==0)
{
return false;
}
}
return true;
}
int main()
{
ll a;
cin>>a;
for(ll i=2;i<a;i++)
{
if (p(i))
{
for(ll j=i;j<a;j++)
{
if(p(j))
{
for(ll k=j;k<a;k++)
{
if(p(k))
{
if(i+j+k==a)
{
cout<<i<<" "<<j<<" "<<k;
return 0;
}
else
{
continue;
}
}
}
}
}
}
}
return 0;
}
by jxyzs @ 2019-09-23 15:40:04
@zhouboxun1205 tle是你的复杂度不对把
by jxyzs @ 2019-09-23 15:41:55
@zhouboxun1205 预处理一下素数,应该可以过
by wally @ 2019-09-23 15:46:50
试试把cin、cout换成scanf、printf
by jxyzs @ 2019-09-23 15:51:31
@wally 输入数据只有一个,几乎没有区别
by jxyzs @ 2019-09-23 15:52:53
@wally 他现在的复杂度是n的三次方
by gdjcwsk @ 2019-09-23 15:58:21
已解决 代码如下:
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
bool p(ll a)
{
ll b=sqrt(a);
for(int i=2;i<=b;i++)
{
if(a%i==0)
{
return false;
}
}
if(a==0)
{
return false;
}
else
{
return true;
}
}
int main()
{
ll a;
cin>>a;
for(ll i=2;i<a;i++)
{
if (p(i))
{
for(ll j=i;j<a;j++)
{
if(p(j))
{
ll k=a-i-j;
if(p(k))
{
cout<<i<<" "<<j<<" "<<k;
return 0;
}
}
}
}
}
return 0;
}
by gdjcwsk @ 2019-09-23 15:58:41
二重循环搞定
by gdjcwsk @ 2019-09-23 16:02:29
谢谢各位大神