for a number N, by remove any digit from it, if it became a lucky* number, N is overlucky number.
you will be given a number, you have to calculate how many of its divisors is overlucky.
Observation: any number having at least one 4 or 7 is overlucky number.
first, make a function isOverlucky() to check weather a number overlucky or not.
now, loop for 1 to square root to find all its divisors and check them.
code:
- #include<bits/stdc++.h>
- using namespace std;
- bool isOverlucky(int n)
- {
- while(n)
- {
- if(n%10==4 || n%10==7)
- return true;
- n/=10;
- }
- return false;
- }
- int main()
- {
- int tc,kk=1, n;
- cin>>tc;
- while(tc--)
- {
- cin>>n;
- int sq=sqrt(n), ans=0;
- for(int i=1;i<=sq;i++)
- {
- if(n%i==0)
- {
- if(overlucky(i))
- ans++;
- if(overlucky(n/i))
- ans++;
- }
- }
- if(sq*sq==n) if(isOverlucky(sq)) ans--;
- cout<<ans<<endl;
- }
- return 0;
- }
Note: if N is square number, then it is calculating twice, don't forget to check that.
*lucky number: any number having the digit only 4 and 7 is lucky number.
example: 4, 444, 74744, 777 etc.
No comments:
Post a Comment