Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Solution {
- public static void main(String[] args) {
- try (Scanner sc = new Scanner(System.in)) {
- int N = sc.nextInt();
- int K = sc.nextInt();
- int sum = 0;
- for(int i = 1; i < N; i++) {
- if(new StringBuilder(i + "").reverse().toString().equals(i + "") && Integer.toString(i, K).equals(new StringBuilder(Integer.toString(i, K)).reverse().toString())) {
- sum += i;
- }
- }
- System.out.println(sum);
- }
- }
- }
Add Comment
Please, Sign In to add comment