fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static boolean isPrime(int n){
  11. if(n <= 1){
  12. return false;
  13. }
  14. if(n <= 3){
  15. return true;
  16. }
  17. if(n % 2 == 0 || n % 3 == 0){
  18. return false;
  19. }
  20. for(int i = 5; i * i <= n; i += 6){
  21. if(n % i == 0 || n % (i + 2) == 0){
  22. return false;
  23. }
  24. }
  25. return true;
  26. }
  27.  
  28. public static String solution(int i) {
  29. String PID = "";
  30. String ID = "";
  31. int num = 1;
  32. int count = 0;
  33. int j;
  34. while(count < i + 1){
  35. num += 1;
  36. for(j = 2; j <= num; j++){
  37. if(num % j == 0){
  38. break;
  39. }
  40. }
  41. if(j == num){
  42. count++;
  43. }
  44. }
  45. PID += Integer.toString(num);
  46. while(PID.length() < 5){
  47. if(num == 2){
  48. num++;
  49. } else{
  50. num += 2;
  51. }
  52. if(isPrime(num)){
  53. PID += Integer.toString(num);
  54. }
  55. }
  56. for(int f = 0; f < 5; f++){
  57. ID += Character.toString(PID.charAt(f));
  58. }
  59. return ID;
  60. }
  61. public static void main (String[] args) throws java.lang.Exception
  62. {
  63. System.out.println(solution(9999));
  64. }
  65. }
Success #stdin #stdout 2.26s 36208KB
stdin
Standard input is empty
stdout
10472