- Given an integer n, find and return the n'th magic number
- A magic number is defined as a number which can be expressed as a power of 7 or sum of unique powers of 7
- First four magic numbers are 7 , 49 , 56 (7 + 49), 343,etc . constraint 1<=n<=pow(10,18) i have implemented the solution as follows:

https://ideone.com/Q8OM0b but it gives me wrong answer,the only difference is that when calculating the value of add we need to apply mod;and the solution is as follows:

how will we know where to apply a mod operator..pls help.

its better to apply after every operation.

say, a + b * c, do it like (a + (b*c) % mod ) % mod

also take care of case of int overflow, either use long long or while(x < 0) x = x + mod.

it didnt work even after applying after every operation.the solution says that we need to apply mod while calculating the power of 7.

then ur implementation is wrong. check it from here..

https://www.google.com/amp/s/www.geeksforgeeks.org/find-nth-magic-number/amp/

Auto comment: topic has been updated by rprudhvi590 (previous revision, new revision, compare).Auto comment: topic has been updated by rprudhvi590 (previous revision, new revision, compare).