Advertisement
j33vansh

Question 1 Peculiar Number

Apr 20th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int sum_of_digit(int n)
  4. {
  5.     if (n == 0)
  6.         return 0;
  7.     return (n%10+sum_of_digit(n/10));
  8. }
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(NULL);
  12.     cout.tie(NULL);
  13.     int t,a,n,res=0,k;
  14.     cin>>t;
  15.     while(t--){
  16.         cin>>a>>n;
  17.         res=pow(a,n);
  18.         k=sum_of_digit(res);
  19.         cout<<k<<"\n";
  20.     }
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement