Algorithm Analysis
Let's find the digits of the number . None of these digits should be equal to zero, since division by 0 is not possible. For example, for the number 4000 or 3405 the answer will be “NO”.
To solve the problem, first, we need to check that none of the digits of the number equals 0, and also that is divisible by and .
Algorithm Implementation
Read the input value .
scanf("%d", &n);
Let . Find the digits of the number .
a = n / 1000; b = n / 100 % 10; c = n / 10 % 10; d = n % 10;
Check that none of the digits of the number equals zero. Check if the number is divisible by and .
if (a != 0 && b != 0 && c != 0 && d != 0 && n % a == 0 && n % b == 0 && n % c == 0 && n % d == 0) printf("YES\n"); else printf("NO\n");
Java Implementation
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int n = con.nextInt(); int a = n / 1000; int b = n / 100 % 10; int c = n / 10 % 10; int d = n % 10; if (a != 0 && b != 0 && c != 0 && d != 0 && n % a == 0 && n % b == 0 && n % c == 0 && n % d == 0) System.out.println("YES"); else System.out.println("NO"); con.close(); } }
Python Implementation
n = int(input()) a = n // 1000 b = n // 100 % 10 c = n // 10 % 10 d = n % 10 if a != 0 and b != 0 and c != 0 and d != 0 and n % a == 0 and n % b == 0 and n % c == 0 and n % d == 0: print("YES") else: print("NO")