Lucky Division - 122A Div 2 | Solution in cpp | Codeforces

 Question



Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.

Input

The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.

Output

In the only line print "YES" (without the quotes), if number n is almost lucky. Otherwise, print "NO" (without the quotes).

Example

input
Copy
47
output
Copy
YES
input
Copy
16
output
Copy
YES
input
Copy
78
output
Copy
NO

Explanation

1.Approach

Take a input n from user then then make that input n into string in different variable

Then check on each index that it have some different numbers than 4 and 7 or not if yes then make flag=1 else keep it zero only.

Then put condition if flag == 0 then cout yes

Or if flag == 1 and n% (all numbers which have 4 and 7 from 1 to 1000  put all ) in the following way

Example

if(flag==1 and (n%4==0 || n%7==0 || n%44==0|| n%47==0 || n%74==0 ||n%77==0 || n%444==0 || n%447==0 || n%474==0 || n%744==0 || n%477==0 || n%747==0 || n%774==0 || n%777==0 ))

cout<<"YES"<<endl;

else cout<<"NO"<<endl;

2.Approach

directly say ki n is divisible by all the value from 1 to 1000 which has only 4 and 7 in this way

Example

  if(n%4==0 || n%7==0 || n%44==0|| n%47==0 || n%74==0 ||n%77==0 || n%444==0 || n%447==0 || n%474==0 || n%744==0 || n%477==0 || n%747==0 || n%774==0 || n%777==0 )

   cout<<"YES"<<endl;

else cout<<"NO"<<endl;

Code

1.Approach Code

#include<bits/stdc++.h>

using namespace std;


#define test     long long T;cin>>T;while(T--)


void solve(){

   int n; cin>>n;

   string x = to_string(n);


   int flag=0;

   for(int i=0;i<x.size();i++){

      if(x[i]=='4' || x[i]=='7') continue;

      else {

        flag=1; break;

      }

   }

   if(flag==1 and (n%4==0 || n%7==0 || n%44==0|| n%47==0 || n%74==0 ||n%77==0 || n%444==0 || n%447==0 || n%474==0 || n%744==0 || n%477==0 || n%747==0 || n%774==0 || n%777==0 ))

   cout<<"YES"<<endl;

   else if(flag==0) cout<<"YES"<<endl;

   else cout<<"NO"<<endl;

}


signed main() {

    //test

    //(if you want to take the more test cases you may uncomment it out)

    solve();

}

2.Approach Code 

#include<bits/stdc++.h>

using namespace std;

int main ()

{

    int n ;

    cin>>n;

    if(n%4==0 || n%7==0 || n%44==0|| n%47==0 || n%74==0 ||n%77==0 || n%444==0 || n%447==0 || n%474==0 || n%744==0 || n%477==0 || n%747==0 || n%774==0 || n%777==0 )

    {

        cout<<"YES";

    }

    else

        {

        cout<<"NO";

    }

    return 0;

}


Hope you might liked my 1st approach which is submitted by me and it is Accepted and working 100% fine.

Previous Post Next Post