Let x n be defined as the smallest positive integer satisfying x n 3 ≡ n 8’s 8 8 8 … 8 ( m o d 1 0 n ) .
Find 2 1 n = 1 ∑ 8 x n .
Hint : x 1 = 2 and x 2 = 4 2 . The answer is a prime number as well.
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.
What would the number theoretic approach yield?
This is one instance in which the CS approach quickly yields the result, but doesn't offer much more insight into the pattern.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
bro, can you help? i don't find any fault in my code.
Log in to reply
When i > 1 0 7 ⇒ i 3 > 1 0 2 1 , which exceeds the maximum that can be stored in unsigned long long int (almost 10^20). You should change k = i * i * i; k %= b to k = (((i * i) % b) * i). This will yield the correct output.
As Calvin points out, a number-theoretic approach to this problem provides a more efficient solution. Here's one that I implemented:
Define P ( n ) : = { x ∣ x 3 ≡ n times 8 8 … 8 8 ( m o d 1 0 n ) } .
First, we note two things:
1) a ∈ P ( n ) ⟹ a ∈ P ( n − 1 ) ∀ n ≥ 2 (obvious)
2) ∀ n ≥ 1 , a ∈ / P ( n ) ∀ 0 < a ≤ 1 0 n ⟹ P ( n ) = ∅ (since x m ≡ ( x m o d 1 0 n ) ( m o d 1 0 n ) )
Combining these two things, we can see that finding P ( 1 ) is easy by just testing the values less than 1 0 and ∀ n ≥ 1 , after finding P ( n ) , to find P ( n + 1 ) , we just need to test the values a which are < 1 0 n and a m o d 1 0 n ∈ P ( n ) . If no solutions are found in a particular iteration, that means no further solutions exist.
So, we implement this in python as follows (using
res
for
P
(
n
)
and
resn
for
P
(
n
+
1
)
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
In fact, the above code provides an efficient (more or less) solution to a more general problem, i.e.,
method(a,m,s)
solves the problem of finding the smallest positive integer solutions to
(
x
n
)
m
≡
n
times
a
a
…
a
a
(
m
o
d
1
0
n
)
∀
1
≤
n
≤
s
where
1
≤
a
≤
9
and
m
≥
1
.
Brute force. There is a method in modulus' mathematics but that is, well, rigorous.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
You indented the
k+=2
line wrong. The code, as it is now, goes into an infinite loop in the
while True:
part when
f(2)
is called.
Thanks., corrected!
Problem Loading...
Note Loading...
Set Loading...
I have used Mathematica code to get the solution:
This gives the values of x n as: 2 , 4 2 , 1 9 2 , 1 9 4 2 , 1 9 4 2 , 7 6 9 4 2 , 1 5 7 6 9 4 2 , 1 1 5 7 6 9 4 2 .
Their sum is 1 3 2 3 4 9 4 6 which divided by 2 is 6 6 1 7 4 7 3 which incidently is prime.