Special number

What should be the approach to solve this question?

Its from an ongoing contest. You will be reported.

Which contest?

I took this test two days before and I think the contest is over. I just want to know how should I approach this problem.

Contest is over bro I honestly I don’t remember I just attend one or two contest daily but this question I snipped and saved so that I can discuss it later.

Which contest is this?

I said I’ve taken it two days before and I don’t remember it is from which contest but the contest is ended on that day so I wouldn’t be reported.

I hope that you’re being honest.
Now, regarding the problem,

There are three ways to get to a special number:

where a,b,c,d,e,f are some constants > 0;

It has been given that Number<=10^9

The maximum possible special number should be 5^1 + 7^{10} = 282,475,254

This means that maximum positive power is 10 for any of the three cases.


  1. You can simply calculate all special numbers <=10^9

  2. Store it in an array

  3. For all values then iterate over it find the minimum difference(not absolute).

1 Like

What is the proof that this contest is not from a live contest. Is there any proof?

Well, There is no proof. You have to trust on me I am attaching this photo here I modified the screenshot because I just replaced my photo to a white box.

I attended this on 2nd december.

Then tell the contest name why you have cropped the contest name in the pic. Tell the contest name and you will get help from anyone otherwise you will be reported.

You mean the best thing we can do is generate all combination and pickup the right one.
Well, I also think of doing this but will it be efficient ?

Listen bro, if someone wants to report it no problem they can report it the point is why you are showing interest in knowing the challenge?? I have got many approaches to solve this but I am still not satisfied. That is why I posted it here.

There will be a total of 135 distinct special numbers for the given constraints(1<=Number<=10^9). You can pre-calculate them just once.
Then for each test case, you can just check with those precalculated numbers for closest special numbers.
Since the list of special numbers is sorted, it will take O(logn) time to search using binary search. Then, O(1) time to calculate minimum cost.
Final Complexity: O(logn)

Thanks a lot bhai. Now I got the point.
Thanks once again and one last thing this is not from a live contest. I have attended it 2 days before. But I am preparing it so that in future I can handle such problems :slight_smile:

Always mention Contest link or problem link so that it can be verified to be not a live contest.

1 Like

For sure. This was my first time posting a discussion on codechef. Now onwards I will post properly so that it can be verify easily.