Advertisement
VladSmirN

cpp2

Oct 14th, 2020
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include "pt4.h"
  2. using namespace std;
  3. long long toTen(long long a , int k){
  4.     long long kr = 1;
  5.     long long ans = 0;
  6.     while(abs(a)>0){
  7.         ans+= kr *(a%10) ;
  8.         kr *= k;
  9.         a/=10;
  10.     }
  11.     return ans;
  12. }
  13. long long toK(long long a , long long k){
  14.     long long ans = 0;
  15.      long long p =1;
  16.     while(a>0){
  17.         ans += p*(a%k);
  18.         a/=k;
  19.         p*=10;
  20.     }
  21.  
  22.     return ans;
  23. }
  24. long long p (long long a , long long b,int k){
  25.     return toK(toTen(a,k)*toTen(b,k),k);
  26. }
  27. void Solve()
  28. {
  29.     Task("TheTri18");
  30.     int X,P,N;
  31.     pt>>X>>N>>P;
  32.     Show(X);
  33.     Show(P);
  34.     Show(N);
  35.  
  36.  long long ans =X;
  37.  for(int i=0;i<N-1;++i){
  38.          Show((int)p(ans,X,P));
  39.    ans = p(ans,X,P);
  40.  }
  41.  pt<<(int)ans;
  42.      Show((int)toTen(X,P));
  43.       Show((int)toK(toTen(X,P),P));
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement