Codeforces 122A Lucky Division

A. Lucky Division





Solution in c++


#include<bits/stdc++.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

using namespace std;

int main()
    int  i,k,m,j,ln,ck,n;
     string arr;
     cin>>arr;
      
     int a = atoi(arr.c_str());
     ln = arr.length();
      
     ck=0;
     for(i=0;i<ln;i++){
          if(arr[i]=='4' || arr[i]=='7'){
               ck++;
          }
         
     }
     if(ck==ln){
          cout<<"YES"<<endl;
     }
     else if(a % 4 == 0 || a % 7 == 0){
          cout<<"YES"<<endl;
     }
     else if(a % 47 == 0){
          cout<<"YES"<<endl;
     }
     else {
          cout<<"NO"<<endl;
     }

}

Post a Comment

3 Comments

  1. Replies
    1. Suppose, 94 is a lucky number because 94%47 = 0 so we need to check our number divider by 47 or not! I hope understand ?

      Delete
  2. Did you even run your code there? Did it get accepted.
    Well your prog. clearly fails for input 370.
    and 370%74=0

    ReplyDelete

If you have any doubts, Please let me know