SeanNers

PrimeAgain

Aug 20th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class PrimeAgain {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6. int soTest = input.nextInt();
  7. int[] nhap = new int[soTest];
  8. int[] xuat = new int[soTest];
  9.  
  10.  
  11. for(int l = 0 ; l <= soTest - 1 ; l ++) {
  12. nhap[l] = input.nextInt();
  13.  
  14. for(int i = 0 ; i <= nhap[l] ; i++ ) {
  15. int root = (int) Math.sqrt(i);
  16.  
  17. for(int j = 2; j <= root ; j++ ) {
  18. if ( (i % j) == 0 ) break;
  19. if ( j == root ) xuat[l] = i;
  20. }
  21. }
  22. }
  23.  
  24. for(int n = 0 ; n <= soTest - 1 ; n++ ) {
  25. System.out.println(xuat[n]);
  26. }
  27.  
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment