We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #168: Number Rotations
Project Euler #168: Number Rotations
+ 9 comments I get 100/100 point :)
Solution:
- Call it as Ab (e.g: if 2345 -> A = 234 and b = 5), and Ab have n length
We need to resolve: Ab * x = bA
=> A = {b[10^(n-1) - x]} / (10x - 1)
(I will explain later)
with:
- x = 1 to 9 - n = 2 to m - b = 1 to 9 - length of A is equal to (n-1)
- We can find A with above conditions. And in Java, we use BigInteger to calculate.
explain:
Ab * x = bA => (10A + b) * x = b * (10^(n-1)) + A => 10x * A + b * x = b * (10^(n-1)) + A => (10x - 1) A = b[ 10^(n-1) - x] => A = {b[10^(n-1) - x]} / (10x - 1)
+ 2 comments This is not clear by last 5 digits...
+ 4 comments #include<stdio.h> int a[105]={0,0,495,5490,55485,55480,98331,98326,98321,98316,98311,98306,41157,75329,75324,75319,75314,75309,28684,28679,28674,28669,19968,19963,62814,62809,96981,96976,90073,90068,32919,32914,32909,32904,32899,32894,86269,86264,86259,20431,20426,20421,34700,34695,50713,50708,50703,50698,93549,93544,93539,93534,27706,27701,81076,81071,74168,74163,63988,63983,6834,6829,6824,6819,6814,40986,75141,75136,75131,75126,75121,75116,28491,28486,28481,28476,28471,28466,5494,5489,5484,5479,5474,5469,12850,12845,12840,12835,28853,28848,82223,16395,16390,16385,16380,16375,59226,59221,59216,59211,59206}; int main (){ int m; scanf ("%d",&m); printf ("%d\n",a[m]); return 0; }
I made a list and successfully passed the tests. You can check the correctness of your code through the list.
+ 2 comments What is test-case 7? Only cannot get it right, weird...
+ 2 comments i thought i understood hte problem, but hte sample input 0/output 0 confuse me
n is between 10, 100
how is 495 a possible right rotation of those nums ?
Load more conversations
Sort 43 Discussions, By:
Please Login in order to post a comment