MEDIUM

Math

# PROBLEM:

You have found a locked safe which is full of Magical Laddu’s. You want to eat them as soon as possible so you start to break the password of the safe. This safe has a digital display which display’s a integer on the screen and according to it you have to find the password of the safe.

# QUICK EXPLANATION:

The algorithm to crack this pattern is If the Number on the display is N then answer for the N will be equal to ( N x N x 11) / 4.

# EXPLANATION:

If you observe the numbers carefully then you will find that the numbers are following some pattern.
The algorithm to crack this pattern is If the Number on the display is N then answer for the N will be equal to ( N x N x 11) / 4.

As the constraints are large so the output will also be very large.
So to handle this constraints in the language like c,c++ you can use array or unsigned long long int.

# SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
unsigned long long int n,cnt=0;
cin>>n;
unsigned long long int k;
k=(nn11)/4;
cout<<k<<“\n”;
}
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
unsigned long long int n,cnt=0;
cin>>n;
unsigned long long int k;
k=(nn11)/4;
cout<<k<<“\n”;
}
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
unsigned long long int n,cnt=0;
cin>>n;
unsigned long long int k;
k=(nn11)/4;
cout<<k<<“\n”;
}
}

Here is my code

#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
int t;
cin>>t;

while(t–)
{
int n;
cin>>n;

int ct = 0;
int tempct = n;
int temp = n;

while(temp!=0)
{
ct++;
temp/=10;
}

int ul = (ct-1)*9;

int num = 0;
for(int j=ct-1;j>=0;j–)
{
num = num + pow(10,j);
}

ul += (n/num);

cout<<(n - ul)<<’\n’;

}
return 0;
}

1 Like