<求助>测试点1,3,5过不去,本蒟蒻不懂
查看原帖
<求助>测试点1,3,5过不去,本蒟蒻不懂
685005
traitrai_100楼主2022/3/8 17:05


import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	final static int MAXN = 10;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int sum = 0;
		int ans = 0;
		BigInteger aa;
		for (int i = 2; ; i++) {
			aa = BigInteger.valueOf(i);
// int 转换为 BigInteger
			if (aa.isProbablePrime(1)) {
// 判断素数,certainty = 1,保证百分百判断成功
				sum += aa.intValue(); 
// BigInteger 转换为 int
				if (sum <= L) {
					System.out.println(aa.intValue());
					ans ++;
				}
				else {
					break;
				}
			}
		}
		System.out.print(ans);
		sc.close();
	}

}

2022/3/8 17:05
加载中...