VC001- Editorial

PROBLEM

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:

Take a value n, divide n with 10 until its remainder is not equal to 0 ,and count the no of iterations as a. Then divide n with 2 until its remainder is not equal to 0 and count the iterations as b. then check if n is not equal to 1 or b is greater than a, if its true print “No” else print “Yes”.

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
#define vll vector

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: