5

I would like to know if there was a way to determine according to this formula: \begin{equation*} \sum_{i=0} \frac{A*i+B \pmod{100}}{100} \end{equation*} and the same with different values of A and B \begin{equation*} \sum_{i=0} \frac{A'*i+B'\pmod{100}}{100}. \end{equation*} If there is a way to determine which one reach 100 the fastest?

Assuming $A, B \in \Bbb N$ and $ A \neq 0$

lopata
  • 319

3 Answers3

2

Not a full answer, but it will sometimes solve the problem. We can recast the question to be for what $n$ does $\sum_{i=0}^n (Ai+B) \pmod {100}$ reach $10000$ If $A$ is coprime to $100$, when we have summed $100$ terms we will have one each of $0$ through $99$, for a sum of $4950$. After two cycles, so at $n=199$ the sum will be $9900$ We then have to ask after how many more terms we have accumulated the missing $100$. I don't see a simple way to get there.

If $A$ is not coprime to $100$, let $d=\gcd(A,100)$. After $\frac {100}d$ terms we have gone through a cycle. The $Ai$ terms will contribute $d\frac 12\cdot \frac {100}d(\frac {100}d-1)=50(\frac {100}d-1)$ to the sum, while the $B$'s will contribute $(B \pmod d)\frac {100}d$ For example, let $A=35$, so $d=5$. Each cycle of $20$ will get $0,5,10\dots 95$ from the $Ai$, summing to $950$. We also get $B \pmod 5$ from the $B$'s, so if $B=8$ this will contribute another $60$ and we get a total of $1010$ from each cycle of $20$ That means that $10$ cycles of $20$ terms $(n=199)$ will sum to $10100$ and we need to stop a few terms earlier. Again I don't see a simple formula to determine how many terms earlier. The one simple observation is that you want $B \pmod d$ to be large to get there quickly.

Ross Millikan
  • 374,822
1

Simulating the summation for given $A$ and $B$ to exactly hit $100$ should be straight forward, maybe except for the case that $100$ can not be reached for the given pair.

Can we say more in advance? Reaching $100$ means $$ 100 = \sum_{i=0}^n \frac{[(iA+B)\pmod {100}]}{100} $$ This gives $$ 10000 = \sum_{i=0}^n [iA+B\pmod {100}] \quad (*) $$

Reaching $100$:

a) To make no progress at all, we need $$ c = i A + B \pmod {100} $$ to vanish for all values $i$. If $c = 0$ then the linear Diophantine equation $$ 100 X - A Y = B \quad (**) $$ has integer solutions $X$, $Y$. This requires $d=\gcd(100, A)$ to be a divisor of $B$. We set $m = B / d$. The equation $100 s + A t = d$ can be solved by the extended Euclidean algorithm for integers $s$ and $t$. Then $(**)$ has the general solution $(X,Y)=(ms - (A/d) k, mt - (100/d) k)$ for $k \in \mathbb{Z}$. We need the spacing $100/d = 1$ for the $Y$ solutions, or $d = 100$. So nothing moves if $B \bmod 100 = 0$ and $\gcd(100,A) = 100$, thus $A \bmod 100 = 0$.

Estimating $n$:

Equation $(*)$ gives \begin{align} 10000 &= \sum_{i=0}^n [iA+B\pmod {100}] \\ &= \sum_{i=0}^n iA+B - q_i 100 \\ &= \frac{n(n+1)}{2} A + (n+1) B - 100 \sum_{i=0}^n q_i \\ &= \frac{A}{2} n^2 + \left(\frac{A}{2}+B\right) n + B - 100 Q \end{align} for a certain $Q$ depending on $A$ and $B$ (this sum of quotients $q_i$ now contains the complication of modulo taking). Assuming $A > 0$, solving for $n$ gives \begin{align} \frac{2}{A}(10000 + 100 Q - B) &= n^2 + \left(1+\frac{2B}{A}\right) n \\ &= \left( n + \frac{1}{2} + \frac{B}{A}\right)^2 - \left( \frac{1}{2} + \frac{B}{A} \right)^2 \end{align}

and \begin{align} n(Q, A, B) &= \sqrt{\frac{2}{A}(10000 + 100 Q - B) + \left( \frac{1}{2} + \frac{B}{A} \right)^2} - \frac{1}{2} - \frac{B}{A} \end{align} with $$ Q = \sum_{i=0}^n q_i = \sum_{i=0}^n \left\lfloor \frac{iA+B}{100} \right\rfloor = \sum_{i=0}^n \frac{iA+B}{100} - \delta_i = S - \sum_{i=0}^n \delta_i $$ with $\delta_i \in [0,1)$.

Results from simulation:

a) Hitting $100$ exactly

The search space for minimal $n$ is $\{ 0, \ldots, 99 \}$ as only $A \bmod 100$ and $B \bmod 100$ matter, that cell repeats. The first smallest results $(A, B, n)$ regarding $n$ are $$ (100, 80, 124) \\ (50, 82, 174) \\ (4, 43, 191) \\ (96, 7, 191) \\ (24, 35, 195) \\ \vdots $$ where the first one is the same as $(0,80,124)$, but $A = 0$ was not feasible.

b) Reaching $100$ or more

In this case the fastest entries $(A,B, n)$ are $$ (0,99,101) \\ (0,98,102) \\ (0,97,103) \\ (0,96,104) \\ (0,95,105) \\ \vdots $$

mvw
  • 34,562
1

If $A$ has no factors in common with $100$, then the first 100 terms will include all the numbers from 0 to 99, and sum to 4950. So will the next 100 terms. So then it is a matter of the next few terms, that add up to 100.
If $A$ is even and not a multiple of 4 nor 5, then the first 50 terms will either be all the odd numbers, and sum to 2500 - so they reach 10000 after 200 terms exactly - or they will be all the even numbers, and sum to 2450, and will only be up to 9800 after 200 terms.
This process can be continued in many other cases. The fastest will be 100i+99, which reaches the total at the 102nd term. The slowest will be 100i+100, which never gets there.

Empy2
  • 50,853