Guest User

Untitled

a guest
Feb 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Solution {
  4.  
  5. public static void main(String[] args) {
  6. try (Scanner sc = new Scanner(System.in)) {
  7. int N = sc.nextInt();
  8. int K = sc.nextInt();
  9. int sum = 0;
  10. for(int i = 1; i < N; i++) {
  11. if(new StringBuilder(i + "").reverse().toString().equals(i + "") && Integer.toString(i, K).equals(new StringBuilder(Integer.toString(i, K)).reverse().toString())) {
  12. sum += i;
  13. }
  14. }
  15. System.out.println(sum);
  16. }
  17. }
  18. }
Add Comment
Please, Sign In to add comment