Sigma function is an interesting function in Number Theory. It is denoted bythe
Greek letter Sigma (σ). This function actually denotes the sum of all divisors of a
number. For example σ(24) = 1+2+3+4+6+8+12+24=60. Sigma of small numbers is easy to
find butfor large numbers itis very difficult to find in a straight forward way.
But mathematicians have discovered a formula to find sigma. If the prime power
decomposition of an integeris
>n=pe11∗pe22∗⋯∗pekk>
>
n
=
p
1
e
1
∗
p
2
e
2
∗
⋯
∗
p
k
e
k
>
Then we can write,
>σ(n)=pe1+11−1p1−1∗pe2+12−1p2−1∗⋯∗pek+1k−1pk−1>
>
σ
(
n
)
=
p
1
e
1
+
1
−
1
p
1
−
1
∗
p
2
e
2
+
1
−
1
p
2
−
1
∗
⋯
∗
p
k
e
k
+
1
−
1
p
k
−
1
>
For some n thevalueof σ(n) is odd andfor others it is even. Given avalue n, you
will have to find how many integers from1to n have even valueof σ.
【Input】
Input starts withaninteger T (≤ 100), denoting thenumberof test cases.
Each case starts withaline containing aninteger n (1 ≤ n ≤ 10^12).
【Output】
For eachcase, print thecasenumberandtheresult.
【Examples】
Sample Input
4
3
10
100
1000
Sample Output
Case1: 1Case2: 5Case3: 83Case4: 947
【Problem Description】
σ(n)为n的所有因子的和,给你一个n,问[1,n]中,σ(i)为偶数的个数有多少个。
【Solution】
数论
将题目给的公式看懂就比较简单了吧。
题目给的公式的每一项起始就是一个等比数列的和。即:
>σ(n)=(1+p1+p21+⋯+pe11)∗(1+p2+p22+⋯+pe22)∗⋯∗(1+pk+p2k+⋯+pekk)>
>
σ
(
n
)
=
(
1
+
p
1
+
p
1
2
+
⋯
+
p
1
e
1
)
∗
(
1
+
p
2
+
p
2
2
+
⋯
+
p
2
e
2
)
∗
⋯
∗
(
1
+
p
k
+
p
k
2
+
⋯
+
p
k
e
k
)
>
LightOJ-1336-Sigma Function-数论-思维【Description】 Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum ...