51Nod-1363 最小公倍数之和
![](https://www.nowcoder.com/equation?tex=Description&preview=true)
![](https://www.nowcoder.com/equation?tex=Calculate%20%5Cquad%20%5Csum_%7Bi%3D1%7D%5E%7Bn%7Dlcm(i%2Cn)&preview=true)
![](https://www.nowcoder.com/equation?tex=Solution&preview=true)
![](https://www.nowcoder.com/equation?tex=%5Csum_%7Bi%3D1%7D%5E%7Bn%7Dlcm(i%2Cn)%0A%5C%5C%3D%5Csum_%7Bi%3D1%7D%5E%7Bn%7D%5Cfrac%7Bi%5Ccdot%20n%7D%7Bgcd(i%2Cn)%7D%0A%5C%5C%3D%5Csum_%7Bd%7Cn%7D%5Csum_%7Bi%3D1%7D%5E%7Bn%7D%5Cfrac%7Bi%5Ccdot%20n%7D%7Bd%7D%5Bgcd(i%2Cn)%3Dd%5D%0A%5C%5C%0A%3D%5Csum_%7Bd%7Cn%7Dn%5Csum_%7Bi%3D1%7D%5E%7B%5Cfrac%7Bn%7D%7Bd%7D%7Di%5Bgcd(i%2C%5Cfrac%7Bn%7D%7Bd%7D)%3D1%5D%0A%5C%5C%3Dn%5Csum_%7Bd%7Cn%7D%5Cfrac%7Bd%5Ccdot%20%5Cvarphi(d)%2B%5Bd%3D1%5D%7D%7B2%7D%0A%5C%5C%3D%5Cfrac%7Bn%7D%7B2%7D%5Ccdot%20(%5Cprod_%7Bp%5Ek%7C%7Cn%7D(1%2B%5Cfrac%7Bp%5E%7B2%5Ccdot%20k%2B1%7D-p%7D%7Bp%2B1%7D)%2B1)%0A&preview=true)
![](https://www.nowcoder.com/equation?tex=Code&preview=true)
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
#define sc scanf
#define itn int
#define STR clock_t startTime = clock();
#define END clock_t endTime = clock();cout << double(endTime - startTime) / CLOCKS_PER_SEC *1000<< "ms" << endl;
using namespace std;
const int N=1e6+5;
const long long mod=1e9+7;
const int inv2=mod+1>>1;
const long long mod2=998244353;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
inline ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}
inline void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=x*(a/b);}
int prime[N],tot=0;
bool vis[N]={};
void pre(){
for(int i=2;i<N;i++){
if(!vis[i])prime[++tot]=i;
for(int j=1;j<=tot&&i*prime[j]<N;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
}
int main(){
pre();
int t;cin>>t;
while(t--){
int n;
sc("%d",&n);
ll ans=1,m=n;
for(int i=1;i<=tot&&1LL*prime[i]*prime[i]<=n;i++){
if(n%prime[i]==0){
int k=0;
while(n%prime[i]==0)n/=prime[i],k++;
ll res=1LL+(ksm(prime[i],2*k+1,mod)-prime[i]+mod)%mod*ksm(prime[i]+1,mod-2,mod);
res%=mod;
ans=ans*res%mod;
}
}
if(n>1)ans=ans*((1LL*n*n-n+1)%mod)%mod;
printf("%lld\n",(ans+1)*m%mod*inv2%mod);
}
}