Skip to content

Instantly share code, notes, and snippets.

@Shravan40
Last active December 24, 2015 18:19
Show Gist options
  • Save Shravan40/6842594 to your computer and use it in GitHub Desktop.
Save Shravan40/6842594 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int count_lucky(int);
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int count = 0;
if(n <= 10)
{
if(n == 4 || n == 7 || n == 8)
{
count = 1;
}
}
else
{
int lim = sqrt(n);
for(int j = 1; j <= lim; j++)
{
if(n % j == 0)
{
if(j * j == n)
{
count += count_lucky(j);
}
count += count_lucky(j) + count_lucky(n/j);
}
}
}
cout<<count<<"\n";
}
return 0;
}
int count_lucky(int p)
{
int lucky = 0;
if(p <= 10)
{
if(p == 4 || p == 7)
{
lucky = 1;
}
}
else
{
while(p > 0)
{
int rem = p%10;
if(rem == 4 || rem ==7)
{
lucky = 1;
p = 0;
}
p /= 10;
}
}
return lucky;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment