Description
First we define:
(1)
lcm(a,b)
, the least common multiple of two integers
a
and
(2)
gcd(a,b)
, the greatest common divisor of two integers
a
and
(3)
[exp]
,
exp
is a logical expression, if the result of
exp
is
true
, then
[exp]=1
, else
[exp]=0
. for example,
[1+2≥3]=1
and
[1+2≥4]=0
.
Now Stilwell wants to calculate such a problem:
Find S(n) mod 258280327 .
Solution
这题是非常有借鉴意义的,它揭露了数论里一个很重要的思想:把大问题化小再通过迭代搞没掉[一般用于这种大于等于的题目](记得ZJOI2016Day1 orzrzz再讲数论的时候某PE题就是用这样的思路,只是那时啥都不懂)
先带着把问题化小的思路进入题目。
观察到
n<=1,000,000
,说明可以线性递推
定义
化解 T(n) :
定义 G(n)=∑d|n[gcd(d,n/d)=1]
则 (1) 式 =G(n/d−1)
G(n)
是积性函数,推导如下:
当
n
的某因子次数为
所以对于
p
为素数,
否则
G(x∗p)=G(x)
不如Eular筛一发得到
G
的值
然后枚举
然后由推导式线性得到
然后前缀和得到
S
<script type="math/tex" id="MathJax-Element-24156">S</script>
然后结束了
Code
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vec;
typedef priority_queue<int> pq;
#define pb push_back
#define ph push
#define fi first
#define se second
inline void Max(int &a,int b){if(a<b)a=b;}
inline void Min(int &a,int b){if(a>b||a==-1)a=b;}
template<class T>void rd(T &a){
a=0;char c;
while(c=getchar(),!isdigit(c));
do a=a*10+(c^48);
while(c=getchar(),isdigit(c));
}
template<class T>void nt(T x){
if(!x)return;
nt(x/10);
putchar(48+x%10);
}
template<class T>void pt(T x){
if(!x)putchar('0');
else nt(x);
}
const int M=1e6+5;
const int P=258280327;
int prime[M],g[M],T[M],f[M],s[M],_,t;
bool mark[M];
inline void Mod_add(int &a,int b){if((a+=b)>=P)a-=P;}
inline void Eular(){
g[1]=1;
for(int i=2;i<M;++i){
if(!mark[i])g[i]=2,prime[t++]=i;
for(int j=0,p;j<t&&1ll*(p=prime[j])*i<M;++j){
mark[i*p]=1;
if(i%p==0){g[i*p]=g[i];break;}
g[p*i]=g[i]<<1;
}
}
for(int d=1;d<M;++d)
for(int k=1;d*k<M;++k)
Mod_add(T[d*k],g[k-1]);
for(int i=1;i<M;++i)
f[i]=((f[i-1]+(i<<1)-1-T[i-1])%P+P)%P;
for(int i=1;i<M;++i)
s[i]=(s[i-1]+f[i])%P;
}
inline void gao(){
int n;cin>>n;
pt(s[n]),putchar('\n');
}
int main(){
for(cin>>_,Eular();_--;)gao();
}