import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader sc=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); int n=Integer.parseInt(sc.readLine()); long sum=0; while(n-->0){ int a=Integer.parseInt(sc.readLine()); if(a<2){System.out.println(0);continue;} sum=2; for (int i = 3; i <=a; i+=2) { if(Pri(i))sum+=i; } out.println(sum); } out.flush(); } static boolean Pri(int n){ for (int i = 2; i*i <=n; i++) { if(n%i==0)return false; } return true; } }
0.0分
1 人评分
C语言训练-最大数问题 (C语言代码)浏览:648 |
【蟠桃记】 (C语言代码)浏览:711 |
A+B for Input-Output Practice (C++代码)浏览:632 |
【明明的随机数】 (C++代码)浏览:834 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:956 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:689 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:583 |
【蟠桃记】 (C语言代码)浏览:1084 |
Hello, world! (C++代码)浏览:1778 |
数对 (C语言代码)浏览:762 |