༺ʚFLYɞ༻ @ 2019-08-04 11:29:26
using namespace std;
bool zs(int a)
{ for(int i=2;i*i<=a;i++)
if(a%i==0)
return 0;
return 1;
}
int main()
{
int a,b,c,n;
cin>>n;
for(a=2;a<=n;a++)
{
if(zs(a)==1)
for(b=2;b<=n-a;b++)
{
if(zs(b)==1)
for(c=2;c<=n-a-b;c++)
{
if(zs(c)==1)
{
if(a+b+c==n)
{
cout<<a<<" "<<b<<' '<<c;
return 0;
}
}
}
}
}
}
by 若如初见 @ 2019-08-04 11:30:19
希望更丰富的展现?使用Markdown
by Disillusionment @ 2019-08-04 11:48:35
希望更丰富的展现?使用Markdown
by Del_Your_Heart @ 2019-08-04 11:50:53
在代码开头加上这个
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <immintrin.h>
#include <emmintrin.h>
by 歌者令 @ 2019-08-11 12:25:00
鬼畜的大括号
by 冰冰手里有糖 @ 2019-08-15 10:17:45
@Del_Your_Heart 能帮下我吗
by Ryo_Yamada @ 2019-09-15 21:30:18
#include <iostream>
#include <cmath>
using namespace std;
bool is_prime(int n){
if(n <= 1)return 0;
for(int i=2; i<=sqrt(n); i++){
if(n % i == 0)return 0;
}
return 1;
}
int main(){
int n;
cin >> n;
for(int i=0; i<n; i++){
if(is_prime(i) == 0)continue;
for(int j=0; j<n; j++){
if(is_prime(j) == 0)continue;
if(is_prime(n - j - i) == 0)continue;
cout << i << " " << j << " " << n-j-i << endl;
return 0;
}
}
return 0;
}
用两层循环试试?