Advertisement
j33vansh

Question 1 Peculiar Number Java Solution

Apr 20th, 2022 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Pecnum {
  4.     public static void main(String[] args) {
  5.         Scanner sc =  new Scanner(System.in);
  6.         int t = sc.nextInt();
  7.  
  8.         while (t-- > 0) {
  9.             int a = sc.nextInt(), n = sc.nextInt();
  10.             long num = (long) Math.pow(a, n);
  11.             int sum = 0;
  12.             while (num > 0) {
  13.                 sum += num % 10;
  14.                 num = num / 10;
  15.             }
  16.             System.out.println(sum);
  17.         }
  18.         sc.close();
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement