题解 | #KiKi求质数个数#
KiKi求质数个数
https://www.nowcoder.com/practice/d3a404ee0f8d41f98bf4707035d91086
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int count=0; for(int i=100;i<=999;i++){ if(is_prime(i)){ count++; } } System.out.println(count); } public static boolean is_prime(int n){ for(int i=2;i<=Math.sqrt(n*1.0);i++){//技巧:i*i<=n if(n%i==0){ return false; } } return true; } }