Chinese Leftovers

Let $g(a, n, b, m)$ be the smallest non-negative solution $x$ to the system:
$x = a \bmod n$
$x = b \bmod m$
if such a solution exists, otherwise $0$.

E.g. $g(2,4,4,6)=10$, but $g(3,4,4,6)=0$.

Let $\phi(n)$ be Euler’s totient function.

Let $f(n,m)=g(\phi(n),n,\phi(m),m)$

Find $\sum f(n,m)$ for $1000000 \le n \lt m \lt 1005000$.

To solve this problem, we need to implement a function that calculates the value of $s(n)$ for any positive integer $n$. Then, we can iterate through all ordered pairs $(u,v)$ of coprime positive integers not exceeding $M$, calculate the corresponding value of $N(u^3/v^3)$, and sum them up to compute $T(M)$. Finally, we will return the result modulo $1,000,000,007$.

Let’s break it down into steps:

Step 1: Implement the function `shift_leftmost_digit(n)` which takes a positive integer `n` as input and returns the integer obtained by shifting the leftmost digit of the decimal representation of `n` to the rightmost position.

Here’s a Python implementation of the `shift_leftmost_digit()` function:

“`python
def shift_leftmost_digit(n):
# Convert the integer to a string
str_n = str(n)

# Shift the leftmost digit to the rightmost position
shifted_str_n = str_n[1:] + str_n[0]

# Convert the resulting string back to an integer
shifted_n = int(shifted_str_n)

return shifted_n
“`

Step 2: Implement the function `N(r)` which takes a positive rational number `r` as input and returns the smallest positive integer `n` such that `s(n) = r * n`. If no such `n` exists, return 0.

Here’s a Python implementation of the `N()` function:

“`python
def N(r):
# Start with n = 1
n = 1

while True:
# Calculate the value of s(n)
shifted_n = shift_leftmost_digit(n)

# Check if s(n) = r * n
if shifted_n == r * n:
return n

# If s(n) > r * n, no solution exists
if shifted_n > r * n:
return 0

# Increment n by 1 and continue the loop
n += 1
“`

Step 3: Implement the function `T(M)` which takes a positive integer `M` as input and returns the sum of `N(u^3/v^3)` where `(u,v)` ranges over all ordered pairs of coprime positive integers not exceeding `M`.

Here’s a Python implementation of the `T()` function:

“`python
def T(M):
result = 0

# Iterate through all ordered pairs (u, v)
for u in range(1, M+1):
for v in range(1, M+1):
# Check if (u, v) are coprime
if math.gcd(u, v) == 1:
# Calculate the value of N(u^3/v^3)
value = N(u**3 / v**3)

# Add the value to the result
result += value

return result % 1000000007
“`

Step 4: Call the `T()` function with the input `M = 200` and print the result modulo `1000000007`.

Here’s the final code:

“`python
import math

def shift_leftmost_digit(n):
str_n = str(n)
shifted_str_n = str_n[1:] + str_n[0]
shifted_n = int(shifted_str_n)
return shifted_n

def N(r):
n = 1

while True:
shifted_n = shift_leftmost_digit(n)

if shifted_n == r * n:
return n

if shifted_n > r * n:
return 0

n += 1

def T(M):
result = 0

for u in range(1, M+1):
for v in range(1, M+1):
if math.gcd(u, v) == 1:
value = N(u**3 / v**3)
result += value

return result % 1000000007

# Call the T() function with M = 200
result = T(200)

# Print the result modulo 1000000007
print(result)
“`

This code will output the value of `T(200)` modulo `1000000007`.

More Answers:
Constrained Sums
$10$-substrings
GCD of Divisors

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts

Don't Miss Out! Sign Up Now!

Sign up now to get started for free!