A sequence ofinteger {an}\lbrace a_n \rbrace{an} can be expressed as:
>an={>0,>2,>3∗an−1−an−22+n+1,n=0n=1n>1>>>
>
a
n
=
{
>
0
,
n
=
0
>
2
,
n
=
1
>
3
∗
a
n
−
1
−
a
n
−
2
2
+
n
+
1
,
n
>
1
>>
>
Now there are two integers nnn and mmm. I'm a pretty girl. I want to find all
b1,b2,b3⋯bpb_1,b_2,b_3\cdots b_pb1,b2,b3⋯bp that 1≤bi≤n1\leq b_i \leq n1≤bi≤n
and bib_ibi is relatively-prime with the integer mmm. Andthen calculate:
>∑i=1pabi>
>
∑
i
=
1
p
a
b
i
>
But I have no timeto solve this problem because I am going todatemy boyfriend
soon. So can you help me?
【Input】
Input contains multiple test cases ( about 150001500015000 ). Each casecontainstwo integers nnn and mmm.1≤n,m≤10^8.
【Output】
For each test case, print the answer of my question(aftermod1,000,000,007).
【Examples】
Sample Input
4 4
Sample Output
14
【Problem Description】
给你an的递推式。设[1,n]内与m互质的数为p1,p2,...,pk,求
>ap1+ap2+⋯+apk>
>
a
p
1
+
a
p
2
+
⋯
+
a
p
k
>
【Solution】
根据递推式求an通项公式:
>2(an−an−1)=an−1−an−2+2n+2>令bn=an−an−1>则2bn=bn−1+2n+2>两边同时减4n得:2(bn−2n)=bn−1−(2n−2)>bn−2nbn−1−2(n−1)=12(n≥2)b1−2=a1−a0−2=0>发现bn−2n=0,bn=2n,即an−an−1=2n>a2−a1=2×2>a3−a2=2×3>a4−a3=2×4>…>an−an−1=2×n>上式全部相加得:an−a1=2×(2+3+⋯+n)>an=2×(1+2+3+⋯+n)=n×(n+1)>>
>
2
(
a
n
−
a
n
−
1
)
=
a
n
−
1
−
a
n
−
2
+
2
n
+
2
>
令
b
n
=
a
n
−
a
n
−
1
>
则
2
b
n
=
b
n
−
1
+
2
n
+
2
>
两
边
同
时
减
4
n
得
:
2
(
b
n
−
2
n
)
=
b
n
−
1
−
(
2
n
−
2
)
>
b
n
−
2
n
b
n
−
1
−
2
(
n
−
1
)
=
1
2
(
n
≥
2
)
b
1
−
2
=
a
1
−
a
0
−
2
=
0
>
发
现
b
n
−
2
n
=
0
,
b
n
=
2
n
,
即
a
n
−
a
n
−
1
=
2
n
>
a
2
−
a
1
=
2
×
2
>
a
3
−
a
2
=
2
×
3
>
a
4
−
a
3
=
2
×
4
>
…
>
a
n
−
a
n
−
1
=
2
×
n
>
上
式
全
部
相
加
得
:
a
n
−
a
1
=
2
×
(
2
+
3
+
⋯
+
n
)
>
a
n
=
2
×
(
1
+
2
+
3
+
⋯
+
n
)
=
n
×
(
n
+
1
)
>>
则题目要 求的为:
>p21+p22+⋯+p2k+p1+p2+⋯+pk>
>
p
1
2
+
p
2
2
+
⋯
+
p
k
2
+
p
1
+
p
2
+
⋯
+
p
k
>
2018-ACM-ICPC-沈阳赛区网络赛-G. Spare Tire-容斥-[1,n]与m互质的数的平方和【Description】 A sequence of integer {an}\lbrace a_n \rbrace{an} can be expressed as: >an={>0,>2,>3∗an−1−an−22+n+1,n=0n=1n...