Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.math.BigInteger;
  6. import java.util.ArrayList;
  7. import java.util.Collections;
  8. import java.util.List;
  9. import java.util.Scanner;
  10.  
  11.  
  12. public class Main {
  13. public static boolean isPal(Long a) {
  14.  
  15. String a3 = Long.toString(a);
  16. String a2 = new StringBuffer(a3).reverse().toString();
  17. if (a3.equals(a2)) return true;
  18. else return false;
  19.  
  20. }
  21.  
  22. public static Long transform(Long from, int radix) {
  23.  
  24. String s = "";
  25. while (from != 0) {
  26. s = (from % radix) + s;
  27. from /= radix;
  28. }
  29.  
  30. return Long.parseLong(s);
  31. }
  32.  
  33.  
  34. public static void main(String[] args) {
  35. Scanner sc = new Scanner(System.in);
  36.  
  37. int col = sc.nextInt();
  38. Long[] mas = new Long[col];
  39. for (int i = 0; i < col; i++) {
  40. mas[i] = sc.nextLong();
  41. }
  42.  
  43. for (int i = 0; i < mas.length; i++) {
  44. Boolean t = false;
  45.  
  46. // System.out.println(mas[i]);
  47.  
  48. for (int j = 2; j <= mas[i] - 2; j++) {
  49.  
  50. // System.out.println(transform(mas[i],j)+" " +j);
  51. if (isPal(transform(mas[i], j))) {
  52. t = true;
  53. break;
  54. }
  55.  
  56. }
  57. if (t) System.out.println("NO");
  58. else System.out.println("YES");
  59.  
  60. }
  61.  
  62.  
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement