EASY

Math

# PROBLEM:

Chef Believe in Unlucky numbers according to him the numbers like 72,2020,755,834 are lucky numbers.And the Numbers like 2,5,11,999,333,7777 are unlucky numbers.

Chef have a number N from which he wants to calculate total number of lucky numbers that N contains inside it.

# QUICK EXPLANATION:

Chef Believe in Unlucky numbers according to him the numbers like 72,2020,755,834 are lucky numbers.And the Numbers like 2,5,11,999,333,7777 are unlucky numbers.

# EXPLANATION:

You have to print the total number of lucky numbers that N contains inside it.
the lucky numbers are the numbers which have identical elements
e.g 88,777,9999,444,etc. all this numbers are lucky numbers.

let’s understand with a testcase
The number 100 contains 18 Unlucky numbers inside it that are (1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99). rest all are lucky numbers i.e 82

# SOLUTIONS:

Setter's Solution

#include
using namespace std;

int main() {
int t;
std::cin >> t;
while(t–)
{
long long n;
long long k=0;
cin>>n;
for(long long i=10;i<=n;i++)
{
int c=0;
int l=0;
long long a=i;long long b=i;
while(b>0)
{
l++;
b=b/10;
}
long long d=i%10;
while(a>0)
{
if(a%10 == d)
c++;
a=a/10;
}
if(c!=l)
k++;
}
cout<<k<<endl;
}
return 0;
}

Tester's Solution

#include
using namespace std;

int main() {
int t;
std::cin >> t;
while(t–)
{
long long n;
long long k=0;
cin>>n;
for(long long i=10;i<=n;i++)
{
int c=0;
int l=0;
long long a=i;long long b=i;
while(b>0)
{
l++;
b=b/10;
}
long long d=i%10;
while(a>0)
{
if(a%10 == d)
c++;
a=a/10;
}
if(c!=l)
k++;
}
cout<<k<<endl;
}
return 0;
}

Editorialist's Solution

#include
using namespace std;

int main() {
int t;
std::cin >> t;
while(t–)
{
long long n;
long long k=0;
cin>>n;
for(long long i=10;i<=n;i++)
{
int c=0;
int l=0;
long long a=i;long long b=i;
while(b>0)
{
l++;
b=b/10;
}
long long d=i%10;
while(a>0)
{
if(a%10 == d)
c++;
a=a/10;
}
if(c!=l)
k++;
}
cout<<k<<endl;
}
return 0;
}