hdu 5382

\(F(n)=\sum_{i=1}^n\sum_{j=1}^n[lcm(i,j)+gcd(i,j)\geq n]\)
\(S(n)=\sum_{i=1}^nF(i)\)
\(F(n)=n^2-\sum_{i=1}^n\sum_{j=1}^n[lcm(i,j)+gcd(i,j)<n]\)
\(F(n)-F(n-1)=n^2-\sum_{i=1}^n\sum_{j=1}^n[lcm(i,j)+gcd(i,j)<n]-(n-1)^2+\sum_{i=1}^{n-1}\sum_{j=1}^{n-1}[lcm(i,j)+gcd(i,j)<n-1]\)
\(F(n)-F(n-1)=2*n-1-\sum_{i=1}^{n-1}\sum_{j=1}^{n-1}[lcm(i,j)+gcd(i,j)=n-1]\)
\(g(n)=\sum_{i=1}^n\sum_{j=1}^n[lcm(i,j)+gcd(i,j)=n]\)
\(g(n)=\sum_{d|n}\sum_{i=1}^{\frac{n}{d}}\sum_{j=1}^{\frac{n}{d}}[gcd(i,j)=1][i*j=\frac{n}{d}-1]\)
\(G(n)=\sum_{i=1}^n\sum_{j=1}^n[gcd(i,j)=1][i*j=n-1]\)
\(G(n)=\sum_{i=1}[gcd(i,\frac{n}{i})=1]\)
\(g(n)=\sum_{d|n}G(d)\)
\(F(n)=F(n-1)+2*n-1-g(n-1)\)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 258280327
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi=acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1000000+10,maxn=2000000+10,inf=0x3f3f3f3f;

ll f[N],g[N],F[N];
int prime[N],cnt;
bool mark[N];
void init()
{
    for(int i=2;i<N;i++)
    {
        if(!mark[i])prime[++cnt]=i,f[i]=1;
        for(int j=1;j<=cnt&&i*prime[j]<N;j++)
        {
            mark[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                f[i*prime[j]]=f[i];
                break;
            }
            f[i*prime[j]]=f[i]+1;
        }
    }
    for(int i=1;i<N;i++)f[i]=qp(2,f[i]);
    for(int i=1;i<N;i++)
        for(int j=i;j<N;j+=i)
            add(g[j],f[j/i-1]);
    for(int i=1;i<N;i++)F[i]=((F[i-1]+2*i-1-g[i-1])%mod+mod)%mod;
    for(int i=1;i<N;i++)add(F[i],F[i-1]);
}
int main()
{
    init();
    int t;scanf("%d",&t);
    while(t--)
    {
        int x;scanf("%d",&x);
        printf("%lld\n",F[x]);
    }
    return 0;
}
/********************

********************/

转载于:https://www.cnblogs.com/acjiumeng/p/11189038.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值