ECMAR20B - Editorial

PROBLEM LINK:

Practice
Contest Link

Author: Anjali Jha
Tester: Arnab Chanda

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

A number is to be taken as input and checked if the original number is divisible by each and every digit present in the number.

EXPLANATION:

A copy of the original number N is stored in a variable called temp and another variable ans is set as “YES”. A loop is run as long as temp > 0. In the loop, each and every digit is extracted and checked. If the digit is 0 or not divisible by N, ans is set as “NO”. Finally, ans is printed.

SOLUTION:

Cpp Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        int temp=n;
        string ans="YES";
        while(temp>0) {
            int dg=temp%10;
            temp/=10;
            if(dg==0 || n%dg!=0) {
                ans="NO";
                break;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
3 Likes