Advertisement
Guest User

Untitled

a guest
Mar 18th, 2022
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Main {
  6. static boolean checkDivisibility (int n, int digit){
  7. return (digit != 0 && n % digit == 0);
  8. }
  9. static boolean allDigitsDivide(int n){
  10. int temp = n;
  11.  
  12. while (temp > 0){
  13. int digit = n % 10;
  14.  
  15. if (!checkDivisibility(n, digit))
  16. return false;
  17. temp /= 10;
  18. }
  19. return true;
  20. }
  21. public static void main(String[] args) {
  22. Scanner scan = new Scanner(System.in);
  23. String input = scan.nextLine();
  24. String[] arr = input.split(" ");
  25. int[] intArr = new int[arr.length];
  26. int counter = 1;
  27.  
  28. int firstNumber = 0;
  29. int secondNumber = 0;
  30.  
  31. for (int i = 0; i < arr.length; i++) {
  32. intArr[i] = Integer.parseInt(arr[i]);
  33. if (i % 2 == 0){
  34. firstNumber = intArr[i];
  35. }
  36. else{
  37. secondNumber = intArr[i];
  38. }
  39. }
  40.  
  41. for (int i = firstNumber; i <= secondNumber; i++) {
  42.  
  43. if (allDigitsDivide(i)) {
  44. counter++;
  45. }
  46. }
  47. System.out.println(counter);
  48. }
  49. }
Advertisement
RAW Paste Data Copied
Advertisement