lindianwu @ 2020-02-13 22:56:23
import java.util.Scanner;
/**
* @Author-- Skipper
*/
public class Main {
public static void main(String[] args) {
boolean flag = false;
Scanner sca = new Scanner(System.in);
int n = sca.nextInt();
for (int i = 2; i <= n - 4; i++) {
if (!isPrime(i))
continue;
for (int j = i; j <= n - 4; j++) {
if (!isPrime(j) || !isPrime(n - j - i)) {
continue;
}
System.out.println(i + " " + j + " " + (n - i - j));
flag = true;
break;
}
if (flag)
break;
}
}
private static boolean isPrime(int num) {
for (int i = 2; i < Math.sqrt(num); i++)
if (num % i == 0)
return false;
return true;
}
}
by lindianwu @ 2020-02-13 22:56:39
为什么最后一个过不去
by ztxtjz @ 2020-02-13 23:01:32
for (int i = 2; i < Math.sqrt(num); i++)
@lindianwu
改成<=
?
by ztxtjz @ 2020-02-13 23:04:03
可尝试一下
by lindianwu @ 2020-02-14 12:06:09
@ztxtjz 呃呃呃,知道哪错了,写太多次没注意到谢谢