Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public class PalindromePrime{
  2.  
  3. public static void main(String[] args){
  4.  
  5. int limit = IO.readInt();
  6. String ans = "";
  7.  
  8. if (limit > 2)
  9. ans = ans + 2 + " ";
  10.  
  11. if (limit == 2){
  12. System.out.println(2);
  13. return;
  14. }
  15. boolean isPrime = false;
  16.  
  17. for(int j=3; j<limit; j++){
  18.  
  19. for(int i=2; i<j; i++){
  20.  
  21. if(j%i == 0){
  22.  
  23. isPrime = false;
  24.  
  25. break;
  26.  
  27. }
  28.  
  29. else isPrime = true;
  30.  
  31. }
  32.  
  33. if(isPrime == true){
  34.  
  35. int countplace = 0;
  36.  
  37. int jchanges = j;
  38.  
  39. int jchangesagain = j;
  40.  
  41. int reverse = 0;
  42.  
  43. while(jchanges/10 != 0){
  44.  
  45. countplace = countplace + 1;
  46. jchanges = jchanges/10;
  47.  
  48. }
  49.  
  50. for(int places = 0; places <= countplace; places++){
  51.  
  52. int part = (jchangesagain%10)*(countplace-places)*10;
  53. reverse = reverse + part;
  54. jchangesagain = jchangesagain/10;
  55.  
  56. }
  57. if(reverse == j)
  58. ans = ans + j + " ";
  59.  
  60. }
  61.  
  62. }System.out.println(ans);
  63.  
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement