Korotkodul

сис-мы счисления

Mar 11th, 2022 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. int n;
  44.  
  45. string to9(int x){
  46.     string r="";
  47.     while (x > 0){
  48.         r += x % 9 + '0';
  49.         x /= 9;
  50.  
  51.     }
  52.     reverse(r.begin(), r.end());
  53.     return r;
  54. }
  55.  
  56.  
  57. ll fr9(string s){
  58.     ll r=0;
  59.     reverse(s.begin(), s.end());
  60.     for (int i=0;i<s.size();++i){
  61.         r += pow(9, i) * (s[i] - '0');
  62.     }
  63.     return r;
  64. }
  65.  
  66.  
  67. string to3(int x){
  68.     string r="";
  69.     while (x>0){
  70.         r += x % 3 + '0';
  71.         x /= 3;
  72.     }
  73.     reverse(r.begin(), r.end());
  74.     return r;
  75. }
  76.  
  77. bool nozer(string s){
  78.     return s.find('0') == string::npos;
  79. }
  80.  
  81.  
  82.  
  83. int main()
  84. {
  85.     ios::sync_with_stdio(0);
  86.     cin.tie(0);
  87.     cout.tie(0);
  88.     cin>>n;
  89.     string nine, three;
  90.     ll ten;
  91.     ll stupid = 0;
  92.     for (int i = 0; i < pow(9, n);++i){
  93.         nine = to9(i);
  94.         if (nine[0] == '0' || nine.size() != n) continue;
  95.         ten = fr9(nine);
  96.         three = to3(ten);
  97.         if (nozer(three)){
  98.             //cout<<ten<<' '<<nine<<' '<<three<<"\n";
  99.             stupid++;
  100.         }
  101.     }
  102.     ll clever = pow(4,n);
  103.     if (stupid == clever){
  104.         cout<<"OK\n";
  105.         cout<<clever<<"\n";
  106.     }
  107.     else{
  108.         cout<<"WA\n";
  109.         cout<<"stupid clever = "<<stupid<<' '<<clever<<"\n";
  110.     }
  111. }
  112.  
Add Comment
Please, Sign In to add comment