Soldier Lines Riddle

Two troops, each with a perfect square number of soldiers, were marching in lines. Upon meeting the other troop, one group would stand fixed on their positions while the other group of soldiers would get in lines with the same numbers of soldiers in each row as much as possible.

As an explicit example below, if there were 16 16 soldiers in one troop and 25 25 in the other, there would be 2 2 ways of merging the lines. As shown, there would be a remainder of 1 1 soldier (marked with red) in either formation.

After joining together, if there were a remainder of 2 2 soldiers in one formation and remainder of 3 3 in the other, what would be the least possible total number of soldiers?


The answer is 410.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Let x x be the number of lines in one group and y y be that in the other for integers y > 2 y > 2 and x > 3 x>3 . We could set up the system of equilavences as show below:

x 2 2 ( m o d y ) x^2 \equiv 2 \pmod y y 2 3 ( m o d x ) y^2 \equiv 3 \pmod x

Then let d = x y d = |x-y| . We can then substitute d 2 d^2 into the equivalences with d 2 > 3 d^2 > 3 or d > 1 d>1 :

x 2 ( x y ) 2 d 2 2 ( m o d y ) x^2 \equiv (x-y)^2 \equiv d^2 \equiv 2 \pmod y y 2 ( y x ) 2 d 2 3 ( m o d x ) y^2 \equiv (y-x)^2 \equiv d^2 \equiv 3 \pmod x

Now we will rewrite the system as equations for some integer quotients n , m n,m :

d 2 = n y + 2 d^2 = ny + 2 d 2 = m x + 3 d^2 = mx +3

Thus, n y m x = 1 ny-mx = 1 , and according to Bezout's identity, gcd(x,y) = 1, and gcd(m,n) = 1.

Solving for x , y x,y , we will get:

y = d 2 2 n y = \dfrac{d^2 -2}{n} x = d 2 3 m x = \dfrac{d^2 -3}{m}

That means d = x y = d 2 3 m d 2 2 n d = |x-y| = | \dfrac{d^2 -3}{m} - \dfrac{d^2 -2}{n}| . Then d m n = ( m n ) d 2 2 m + 3 n = ( m n ) ( d 2 2 ) + n = ( m n ) ( n y ) + n dmn = |(m-n)d^2 -2m +3n|= |(m-n)(d^2 - 2) + n| = |(m-n)(ny) + n| . Dividing by n n both sides, d m = ( m n ) y + 1 dm = |(m-n)y + 1| . Thus, d m 1 1 ( m o d y ) dm \equiv |1| \equiv 1 \pmod y for y > x y>x .

Let us check cases, where y > x y > x and that y = x + d y = x+d .

From the above equation, we could also set up d m 1 ( m o d m n ) dm \equiv 1 \pmod{m-n} . Since m n 0 ( m o d m n ) m-n \equiv 0 \pmod{m-n} , then m n ( m o d m n ) m \equiv n \pmod{m-n} . Thus, d d is a modular inverse of m m and n n . Then d n 1 ( m o d m n ) dn \equiv 1 \pmod{m-n} , and ( d 2 2 ) n d 2 n ( m o d m n ) (d^2 -2) n \equiv d-2n \pmod{m-n} .

Substituting n y = d 2 2 ny = d^2 - 2 , we will get n 2 y d 2 n ( m o d m n ) n^2 y \equiv d - 2n \pmod{m-n} .

n 2 y 2 n d ( m o d m n ) n^2 y - 2n \equiv d \pmod{m-n} .

( n y ) 2 2 n y d y ( m o d y ( m n ) ) (ny)^2 - 2ny \equiv dy \pmod{y(m-n)} .

( m x + 1 ) 2 2 ( m x + 1 ) d y ( m o d y ( m n ) ) (mx+1)^2 -2(mx +1) \equiv dy \pmod{y(m-n)} .

( m x ) 2 1 d y ( m o d y ( m n ) ) (mx)^2 - 1 \equiv dy \pmod{y(m-n)} .

( m x 1 ) ( m x + 1 ) d y ( m o d y ( m n ) ) (mx-1)(mx+1) \equiv dy \pmod{y(m-n)} .

( m x 1 ) ( n y ) d y ( m o d y ( m n ) ) (mx-1)(ny) \equiv dy \pmod{y(m-n)} .

( m x 1 ) ( n ) d ( m o d ( m n ) ) (mx-1)(n) \equiv d \pmod{(m-n)} .

m x 1 d 2 ( m o d ( m n ) ) mx-1 \equiv d^2 \pmod{(m-n)} .

m x + 3 d 2 + 4 ( m o d ( m n ) ) mx+3 \equiv d^2 +4\pmod{(m-n)} .

d 2 d 2 + 4 ( m o d ( m n ) ) d^2 \equiv d^2 +4\pmod{(m-n)} .

Finally, 4 0 ( m o d m n ) 4 \equiv 0 \pmod{m-n} . That means m n 4 m-n|4 , and the value of m n m-n is either 1 1 , 2 2 , or 4 4 .

However, by checking values of d = 2 , 3 , 4 d =2,3,4 , no answers can be found:

For d = 2 d=2 , d 2 = 4 3 ( m o d x ) d^2 = 4 \equiv 3 \pmod x ; 1 0 ( m o d x ) 1 \equiv 0 \pmod x , which is contradicted because x > 3 x > 3 .

For d = 3 d=3 , d 2 = 9 2 ( m o d y ) d^2 = 9 \equiv 2 \pmod y ; 7 0 ( m o d y ) 7 \equiv 0 \pmod y . Only y = 7 y=7 works, leading to x = 7 3 = 4 x = 7- 3 = 4 , but d 2 3 = 9 3 = 6 d^2 - 3 = 9-3=6 , which is not divisible by 4 4 and so contradicted.

For d = 4 d=4 , d 2 = 16 2 ( m o d y ) d^2 = 16 \equiv 2 \pmod y ; 14 0 ( m o d y ) 14 \equiv 0 \pmod y . Again, only y = 7 y=7 works, leading to x = 7 4 = 3 x = 7- 4 = 3 , but d 2 3 = 16 3 = 13 d^2 - 3 = 16-3=13 , which is not divisible by 3 3 and so contradicted.

By all means, we can conclude that d > m n d > m-n . Returning to d m = ( m n ) y + 1 dm = (m-n)y + 1 . d ( m 1 d ) = ( m n ) y d(m - \dfrac{1}{d}) = (m-n)y . Since d > m n d > m-n , then y > m 1 d y > m - \dfrac{1}{d} . With both y , m y,m being integers, we can conclude y > m y > m .

Returning to d m 1 ( m o d y ) dm \equiv 1 \pmod y . d 2 m d ( m o d y ) d^2 m \equiv d \pmod y . Since d 2 = n y + 2 d^2 = ny + 2 , then d 2 2 ( m o d y ) d^2 \equiv 2 \pmod y . Thus, 2 m d ( m o d y ) 2m \equiv d \pmod y , and m = d m ( m o d y ) m = d-m \pmod y . We know that y > m y>m and y > d y>d , so that means y > d m y > |d-m| . Here are the 3 3 possible scenarios:

First, d m = 0 d-m = 0 , that makes m = 0 ( m o d y ) m = 0 \pmod y , which is contradicted because y > m y > m .

Second, d m < 0 d-m < 0 , with y > m y > m and y > d y > d , the resulting 2 m d 0 ( m o d y ) 2m-d \equiv 0 \pmod y only applies for y = 2 m d y = 2m-d . For any higher quotient before y y will make an inequality. Then x + d = 2 m d x+d = 2m-d , and so x = d 2 3 m = 2 ( m d ) x = \dfrac{d^2 -3}{m} = 2(m-d) . Rearranging the quadratic equation, we will obtain d 2 + ( 2 m ) d ( 2 m 2 + 3 ) = 0 d^2 +(2m)d-(2m^2 + 3) = 0 . By the quadratic formula, d = m + 3 ( m 2 + 1 ) d = -m + \sqrt{3(m^2 + 1)} . In order to yield integer d d , m 2 + 1 = 3 t 2 m^2 + 1 = 3t^2 for some integer t t . However, per modulo 3 3 , m 2 1 ( m o d 3 ) m^2 \equiv -1 \pmod 3 , and for all perfect squares modulo 3 3 , it only results in a remainder of 1 1 or 0 0 only. Thus, this is contradicted.

As a result, y > d m > 0 y> d-m > 0 and y > m y > m . Thus, in order for the remainders m d m ( m o d y ) m \equiv d-m \pmod y to be true, it needs to be m = d m m = d-m . Thus, d = 2 m d = 2m . Then d 2 = 4 m 2 = m x + 3 d^2 = 4m^2 = mx+3 , and so m ( 4 m x ) = 3 m(4m-x) = 3 . That means m 3 m|3 , leaving only m = 1 m = 1 or m = 3 m=3 , but for m = 1 m=1 , it will cause d = 2 d=2 , which is shown to be contradicted earlier.

Since no lesser d d is applicable, the other cases, where x > y x>y wouldn't result in least possible solution.

Finally, m = 3 m=3 ; d = 6 d=6 , and 36 2 ( m o d y ) 36 \equiv 2 \pmod y . 34 = 2 × 17 0 ( m o d y ) 34 = 2\times 17 \equiv 0 \pmod y . Clearly, n = 2 n=2 and y = 17 y = 17 , and x = 17 6 = 11 x = 17-6 =11 .

Therefore, the total number of soldiers = 1 1 2 + 1 7 2 = 410 11^2 + 17^2 = \boxed{410} .

Checking the answers, we can prove the solution:

1 1 2 = 17 × 7 + 2 11^2 = 17\times 7 + 2

1 7 2 = 11 × 26 + 3 17^2 = 11\times 26 + 3

Hi, firstly, I think you meant to say "Perfect Squares", rather than "Perfect Numbers". Second thing is that 7 2 7^2 and 4 6 2 46^2 can also be a solution, right?

Log in to reply

Ah, yes, sorry, it's perfect square. For the solution, I'll amend as least amount possible then.

Worranat Pakornrat - 2 years ago

1
print(min([m*m+n*n for (m,n) in [(m,n) for m in range(1,1000) for n in range(1,1000)] if m*m%n==2 and n*n%m==3]))

dirty little one-liner

Noe Blassel - 1 year, 12 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...