Codeforces 185D Visit of the Great (the foundations of mathematics, number theory)

The meaning of problems

Given \ (Q (\ leq 10 ^ 5) \) queries, each query four numbers \ (k, l, r, p (k \ leq 10 ^ 6, 0 \ leq l \ leq r \ leq 10 ^ {18 is}, P \ Leq 10 ^. 9) \) , \ (P \) is the number of quality, and
\ [lcm (k ^ {2 ^ l} + 1, k ^ {2 ^ {l + 1}} + 1, ..., k ^ {2 ^ r} +1) \% p \]

My problem solving process

Up to a playing table to find the law, surprised to find
\ [gcd (k ^ {2 ^ x} + 1, k ^ {2 ^ {x + y}} + 1) = \ begin {cases} 1 & k \ text { is even} \\ 2 & k \
text {is odd} \\\ end {cases} \] then a matter of course, according to the \ (lcm (a, b) = \ frac {ab} {gcd (a, b)} \ ) With
\ [Ans = \ begin {cases } \ prod \ limits_ {i = l} ^ r (k ^ {2 ^ i} +1) & k \ text {is even} \\\ frac {\ prod \ limits_ {i = l} ^ r
(k ^ {2 ^ i} +1)} {2 ^ {rl}} & k \ text {is odd} \\\ end {cases} \] look \ (P = \ Prod \ limits_ {I} = ^ R & lt L ({K ^ I ^ 2} + 1'd) \) .
\ [\} the begin {align = left & P = (K ^ L ^ {2} + 1'd) ({2 ^ K ^ {l + 1}} + 1) ... (k ^ {2 ^ r} +1) \\ & = ({(k ^ {2 ^ {l}})} ^ {2 ^ 0} + { (k ^ {2 ^ {l }})} ^ {0}) ({(k ^ {2 ^ {l}})} ^ {2 ^ 1} + {(k ^ {2 ^ {l}}) } ^ {0}) ... ( {(k ^ {2 ^ {l}})} ^ {2 ^ {rl}} + {(k ^ {2 ^ {l}})} ^ {0}) \\ & = ({(k ^ {2 ^ {l}})} ^ {(001) _2} + {(k ^ {2 ^ {l}})} ^ {0}) ({(k ^ { 2 ^ {l}})} ^ {(010) _2} + {(k ^ {2 ^ {l}})} ^ {0}) ... ({(k ^ {2 ^ {l}}) } ^ {(10 ... 0) _2} + {(k ^ {2 ^ {l}})} ^ {0}) \\\ end {align} \]
Binary method of view, then, if every ride out, is that there \ (rl \) binary bits, each bit can be 0 or 1. Thus
\ [\ begin {align} P & = \ sum \ limits_ {j = 0} ^ {2 ^ {r-l + 1} -1} {(k ^ {2 ^ {l}})} ^ j \\ & = \ frac {{(k ^ {2 ^ l})} ^ {2 ^ {r-l + 1}} - 1} {k ^ {2 ^ l} -1} & k \ not = 1 \\ & = \ frac {k ^ {
2 ^ {r + 1}} - 1} {k ^ {2 ^ l} -1} & k \ not = 1 \\\ end {align} \] by the Euler's theorem \ (GCD (K, P) \ Not =. 1 \) , i.e. \ (k \% p \ not = 0 \) when, \ (K ^ {2 ^ L} \ equiv K ^ {2 ^ L \% (P -1)} (MOD \ P) \) . Therefore, this \ (K \) is also very high power demand, the old routines. When \ (p | k \) , the apparently \ (k ^ {2 ^ l } -1 \ equiv k ^ {2 ^ {r + 1}} - 1 \ equiv (-1) (mod \ p) \ ) , and \ (GCD (K ^ 2 ^ {-1} L, P) =. 1 \) , so obviously \ (P =. 1 \) .

In the remaining case, \ (GCD (K ^ 2 ^ {-1} L, P) =. 1 \) when engaged is also very good, direct inversing do out on the line. But \ (gcd (k ^ {2 ^ l} -1, p) \ not = 1 \) i.e. \ (p | (k ^ { 2 ^ l} -1) \) , since the inverse does not exist, situation is a bit complicated. Thus constructed observed and the following equation:
\ [^ {K ^ {2}}. 1 R & lt + -. 1 = (L ^ K ^ {2} -1) (2 ^ {K ^. 1} + {R & lt -2 ^ l} + k ^ {2 ^ {r + 1} -2 * 2 ^ l} + k ^ {2 ^ {r + 1} -3 * 2 ^ l} + ... + k ^ {2 ^ {r +1} -2 ^ {r-l
+ 1} * 2 ^ l}) \] obviously \ (T = k ^ {2 ^ {r + 1} -2 ^ l} + k ^ {2 ^ {r + 1} -2 * 2 ^ l} + k ^ {2 ^ {r + 1} -3 * 2 ^ l} + ... + k ^ {2 ^ {r + 1} -2 ^ {r-l + 1} * 2 ^ l} \ ) is the result we want.
\ [\ Begin {align} T & = k ^ {2 ^ {r + 1} -2 ^ l} + k ^ {2 ^ {r + 1} -2 * 2 ^ l} + k ^ {2 ^ {r +1} -3 * 2 ^ l} + ... + k ^ {2 ^ {r + 1} -2 ^ {r-l + 1} * 2 ^ l} \\ & = k ^ {2 ^ { r + 1}} (\ frac {1} {k ^ {2 ^ {l}}} + \ frac {1} {{(k ^ {2 ^ {l}})} ^ 2} + \ frac {1 } {{(k ^ {2 ^ {l}})} ^ 3} + ... + \ frac {1} {{(k ^ {2 ^ {l}})} ^ {2 ^ {r-l +1}}}) \\ & = k ^ {2 ^ {r + 1}} (\ frac {1} {k ^ {2 ^ {l}}} + (\ frac {1} {k ^ {2 ^ {l}}}) ^ 2 + (\ frac {1} {k ^ {2 ^ {l}}}) ^ 3 + ... + (\ frac {1} {k ^ {2 ^ {l} }}) ^ {2 ^ { r-l + 1}}) \\\ end {align} \]
Because of \ (P | (K ^ L ^ {2} -1) \) , i.e. \ (K L ^ 2 ^ {} \ equiv. 1 (MOD \ P) \) , found \ (gcd (k ^ {2 ^ L}, P) =. 1 \) , therefore \ (\ frac {k ^ { 2 ^ {r + 1}}} {k ^ {2 ^ l}} \ equiv k ^ {2 ^ {r + 1} } (MOD \ P) \) . it is therefore clear
\ [\ begin {align} T & \ equiv k ^ {2 ^ {r + 1}} (1 + 1 + 1 + ... + 1) (mod \ p ) \\ & \ equiv k ^ {
2 ^ {r + 1}} 2 ^ {r-l + 1} (mod \ p) \\\ end {align} \] can now easily solve for \ (T \ ) . This problem is over.

Reflection

1. Why
\ [gcd (k ^ {2 ^ x} + 1, k ^ {2 ^ {x + y}} + 1) = \ begin {cases} 1 & k \ text {is even} \\ 2 & k \ text {is odd} \\\ end {
cases} \] looked at, explanations are given in the official \ (y = 1 \) demonstrated when, quite ingenious.

Set \ (D = GCD (K ^ {2 ^ X} +. 1, K ^ {2 ^ {X +. 1}} +. 1) \) . Thus \ (k ^ {2 ^ x } \ equiv-1 (mod \ D) \) . squared to give \ (K ^ {2 ^ {X +. 1}} \ equiv. 1 (MOD \ D) \) . However, \ (k ^ {2 ^ { x + 1}} \ equiv-1 (MOD \ d) \) , we can only have \ (d \ leq2 \) . again (k \) \ parity discussions to be concluded.

2. In fact, the last paragraph of the discussion I chose a detour. Observed \ (K L ^ 2 ^ {} \ equiv. 1 (MOD \ P) \) , it is clear that there are \ (P \ equiv \ sum \ limits_ {j = 0} ^ {2 ^ {r-l + 1 } -1} {(k ^ { 2 ^ {l}})} ^ j \ equiv 2 ^ {r-l + 1} (mod \ p) \) a.

Guess you like

Origin www.cnblogs.com/zhugezy/p/12008879.html