Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PalindromePrime{
- public static void main(String[] args){
- int limit = IO.readInt();
- String ans = "";
- if (limit > 2)
- ans = ans + 2 + " ";
- if (limit == 2){
- System.out.println(2);
- return;
- }
- boolean isPrime = false;
- for(int j=3; j<limit; j++){
- for(int i=2; i<j; i++){
- if(j%i == 0){
- isPrime = false;
- break;
- }
- else isPrime = true;
- }
- if(isPrime == true){
- int countplace = 0;
- int jchanges = j;
- int jchangesagain = j;
- int reverse = 0;
- while(jchanges/10 != 0){
- countplace = countplace + 1;
- jchanges = jchanges/10;
- }
- for(int places = 0; places <= countplace; places++){
- int part = (jchangesagain%10)*(countplace-places)*10;
- reverse = reverse + part;
- jchangesagain = jchangesagain/10;
- }
- if(reverse == j)
- ans = ans + j + " ";
- }
- }System.out.println(ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement