题目:中位因数
题解:找到i的倍数j,那么i和j/i就有可能是j的中位数,保证i<j/i,既然是中位数,那么i就应该所有因子左边的最大值,所以用a来维护。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int inf = 0x7f7f7f7f;
const int N = 1e6+10;
const ll mod = 1e9+7;
int read(){
char ch=getchar();int x=0,f=1;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int random(int n){return (ll)rand()*rand()%n;}
int a[N];
ll f[N];
void init(){
for(int i = 1;i < N;i++){
for(int j = i;j < N;j += i){
int u = i,v = j/i;
if(u > v) swap(u,v);//u<v
if(u > a[j]){
a[j] = u;
f[j] = (u+v)/2;
}
}
}
for(int i = 1;i < N;i++){
f[i] += f[i-1]%mod;
}
}
int main(){
//srand((unsigned)tmie(0));
//freopen("out.txt","w",stdout);
init();
int n = read();
while(n--){
int x = read();
cout<<f[x]<<endl;
}
return 0;
}