[絕對能看懂!]Deciphering Password(積性函式+線性篩+素數分解)
描述
Xiaoming has just come up with a new way for encryption, by calculating the key from a publicly viewable number in the following way:
Let the public key N = A^B, where 1 <= A, B <= 1000000, and a0, a1, a2, …, ak-1 be the factors of N, then the private key M is calculated by summing the cube of number of factors of all ais. For example, if A is 2 and B is 3, then N = A^B = 8, a0 = 1, a1 = 2, a2 = 4, a3 = 8, so the value of M is 1 + 8 + 27 + 64 = 100.
However, contrary to what Xiaoming believes, this encryption scheme is extremely vulnerable. Can you write a program to prove it?
輸入
There are multiple test cases in the input file.
Each test case starts with two integers A, and B. (1 <= A, B <= 1000000). Input ends with End-of-File.
輸出
For each test case, output the value of M (mod 10007) in the format as indicated in the sample output.
提示
2008 Asia Hangzhou Regional Contest Online.
分析
給定A,B,求
的各個因子的因子個數的立方和。比較拗口,用公式敘述。設N的因子為
,對於任意
,求
的因子個數 ,然後求得最終結果
,輸出結果取餘10007。
定義1:函式
是
的因子個數。例如,4的因子個數為3個,分別是1,2,4,則
。
定義2:函式
是
的各個因子的立方和,即
。
引理1:
和
是積性函式(multiplicative function)。事實上兩者是除數函式(divisor function)的兩種特殊情況,而除數函式是積性函式。積性函式
具有如下性質:
(1)
(2)
,當且僅當a,b互質
滿足上面兩條性質,那麼我們說
是積性函式。
引理2:積性函式的除數函式還是積性函式。
證明(可略過):
{
假設
是積性函式,令
為
的除數函式。假設
(即m,n互質),則有:
即:
由於
,
,
,故
(證明略,高代基礎)。因此由
為積性函式可得:
對於
的任意一個因子,我們都可以將其寫作
其中
且
。故:
得證
為積性函式。
參考:
http://sites.millersville.edu/bikenaga/number-theory/divisor-functions/divisor-functions.html
}
正式解題:
題目要我們求的其實就是