Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll,ll> pll;
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
- #define fi first
- #define se second
- #define pb push_back
- #define eb emplace_back
- ll const MOD=1000000007;
- const int M= 2e5 + 10;
- ll cost[M+10];
- bool vis[M+10];
- ll n,m,a,b;
- bool ok=false;
- vector<ll>v[M+1];
- ll tar;
- bool f=false;
- void call(ll s)
- {
- if(ok)return;
- if(s==tar)
- {
- f=true;
- return;
- }else if(s>tar)
- {
- return ;
- }
- call(s*10);
- call(s*20);
- }
- int main()
- {
- fastread();
- while(1)
- {
- f=false;
- cin>>tar;
- call(1);
- if(f)cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- }
- // stack by RECURTION
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<ll,ll> pll;
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
- #define fi first
- #define se second
- #define pb push_back
- #define eb emplace_back
- ll const MOD=1000000007;
- const int M= 2e5 + 10;
- ll cost[M+10];
- bool vis[M+10];
- ll n,m,a,b;
- bool ok=false;
- vector<ll>v[M+1];
- ll tar;
- bool f=false;
- int main()
- {
- fastread();
- while(1)
- {
- cin>>tar;
- stack<ll>s;
- s.push(1);
- ll a;
- bool f=false;
- while(!s.empty())
- {
- a=s.top();
- s.pop();
- if(a==tar)
- {
- f=true;
- break;
- }else if(a>tar)s.pop();
- if(a*10<=tar) s.push(a*10);
- if(a*20<=tar) s.push(a*20);
- }
- if(f)cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- }
Add Comment
Please, Sign In to add comment