Working with big numbers is not trivial; you cannot just use built-in types like int
, double
, long
, etc for this. In order to calculate a number with 100000 digits, you need to have more than 300000 bits (a few kilobytes); this is in no way easy. Instead, you can print the answer without calculating it!
Saying that a number num
is divisible by 2, 3, 5 and 7 is the same as num % 210 == 0
. So the answer to your question looks like this:
100000000000... (really many zeros) ...00000xy0
All you need is to find two digits x and y, and print the above "number".
So you have to calculate pow(10, 99999) % 210
without calculating pow(10, 99999)
. To do it, start with pow(10, 0) = 1
and multiply by 10 successively:
pow(10, 0) % 210 = 1
pow(10, 1) % 210 = (1 * 10) % 210 = 10
pow(10, 2) % 210 = (10 * 10) % 210 = 100
pow(10, 3) % 210 = (100 * 10) % 210 = (1000 % 210) = 160
pow(10, 4) % 210 = (160 * 10) % 210 = (1600 % 210) = 130
pow(10, 5) % 210 = (130 * 10) % 210 = (1300 % 210) = 40
...
After you calculate pow(10, 99999) % 210
in this manner (suppose it's xyz
), adding 210 - xyz
will make the number divisible by 210. So, to output the answer, print 1
, then print 99996 times 0
, then print 210 - xyz
.