### PROBLEM LINK:

https://www.codechef.com/problems/GOC2003

https://www.codechef.com/GMCD1601/problems/GOC2003

**Author:** https://www.codechef.com/users/tayyabali

**Tester:** https://www.codechef.com/users/tayyabali

**Editorialist:** https://www.codechef.com/users/nileshdbit

### DIFFICULTY:

MEDIUM

### PROBLEM:

A time machine gives a 4 digit number (N) to Pradyuman, from which he needs to find a secret number, this number refers to the book number in which he will get the hint of next crime which is going to happen in the city. Pradyuman multiplies the N with equation “X^2+Y*4” and obtains the R, Where X is the day, Y is month in the DD and MM form. The date is current date on which Pradyuman got the N.

For a next number Pradyuman increments the date and re-calculates the number from the same equation. Pradyuman now keeps track of individual digits from 0 to 9 that he receives in R, and again finds the number until he sees all the digits (from 0 to 9) appeared in the results obtained so far. When date reaches to the end of month, then month will get incremented.

When Pradyuman gets all the digits in R, he selects the last R which gives him the last digit to complete from 0 to 9. R is then appended to the four digits which he got from the time machine and that’s the book number which he has to refer to work on the new case.

### AUTHOR’S AND TESTER’S SOLUTIONS:

```
#include <stdio.h>
#include<stdlib.h>
int lookup[10];
int checkFinished();
void recordDigits(int R);
int concatenate(int x, int y);
int main(void) {
//Input the N and date
int N,X,Y,R,FinalR;
int flag=0;
int c;
int count;
scanf("%d",&N);
scanf("%d",&X);
scanf("%d",&Y);
// Initilize the lookup array
for(count=0;count<10;count++)
{
lookup[count]=0;
}
//logic
while(1)
{
R = ((X*X)+(Y*4))*N;
//printf("%d\n",R);
recordDigits(R);
if(flag=checkFinished()==1)
{
//printf("This is the R %d ",R);
FinalR=concatenate(N,R);
printf("%d",FinalR);
exit(0);
}
//increment the date
X=X+1;
if(Y==4||Y==6||Y==9||Y==11)
{
if(X>30)
X=1;
}
else
{
if(X>31)
X=1;
}
}
return 0;
}
void recordDigits(int R)
{
int value = R;
while (value > 0) {
int digit = value % 10;
lookup[digit]=1;
value /= 10;
}
}
int checkFinished()
{
int count;
for(count=0;count<10;count++)
{
if(lookup[count]==0)
return 0;
}
return 1;
}
int concatenate(int x, int y)
{
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}
```