Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- int n;
- string to9(int x){
- string r="";
- while (x > 0){
- r += x % 9 + '0';
- x /= 9;
- }
- reverse(r.begin(), r.end());
- return r;
- }
- ll fr9(string s){
- ll r=0;
- reverse(s.begin(), s.end());
- for (int i=0;i<s.size();++i){
- r += pow(9, i) * (s[i] - '0');
- }
- return r;
- }
- string to3(int x){
- string r="";
- while (x>0){
- r += x % 3 + '0';
- x /= 3;
- }
- reverse(r.begin(), r.end());
- return r;
- }
- bool nozer(string s){
- return s.find('0') == string::npos;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n;
- string nine, three;
- ll ten;
- ll stupid = 0;
- for (int i = 0; i < pow(9, n);++i){
- nine = to9(i);
- if (nine[0] == '0' || nine.size() != n) continue;
- ten = fr9(nine);
- three = to3(ten);
- if (nozer(three)){
- //cout<<ten<<' '<<nine<<' '<<three<<"\n";
- stupid++;
- }
- }
- ll clever = pow(4,n);
- if (stupid == clever){
- cout<<"OK\n";
- cout<<clever<<"\n";
- }
- else{
- cout<<"WA\n";
- cout<<"stupid clever = "<<stupid<<' '<<clever<<"\n";
- }
- }
Add Comment
Please, Sign In to add comment