VC001- Editorial

Vice City

PROBLEM LINK

https://www.codechef.com/CDHN2021/problems/VC001

Author: Aman Nadaf

Tester: Aman Nadaf

Editorialist: Aman Nadaf

DIFFICULTY:

easy

PREREQUISITES:

None

PROBLEM:

You are playing GTA Vice City. Initially, you have one dollar, but you have somehow acquired two cheat codes.
The first cheat code multiplies the amount of money you own by 10, while the second one multiplies it by 20. The cheat codes can be used any number of times.
You want to have exactly N dollars. Now you are thinking: can you achieve that by only using some sequence of cheat codes?

EXPLANATION:

After Reading the Value of N. We divide N by 10 continuously until N is divisible by 10 and we store the count in variable a. Then we divide N by 2 continuously until N is divisible by 2 and we store the count in variable b. then we check if N is not equal to 1(N!=1) or count of b greater than a (b>a) .if this is the case then we print “No” else we print “Yes”.

SOLUTIONS:

Setter's Solution



#include <bits/stdc++.h>
#include <math.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vll vector<long long int>

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    std::ios::sync_with_stdio(false);

    ll t;
    cin >> t;
    while (t--)
    {
         ll n;
	    cin>>n;
	    ll a=0,b=0;
	    while(n%10==0){
	        n/=10;
	        a++;
	    }
	    while(n%2==0){
	        n/=2;
	        b++;
	    }
	    if(n!=1 || b>a){
	        cout<<"No"<<endl;
	    }else{
	        cout<<"Yes"<<endl;
	    }
    }
}

Feel free to share your approach here. Suggestions are always welcomed. :slight_smile:
.