列表

详情


NC205040. 小V的和式

描述

VMware实习生小V酷爱数论,他在研究数论书时获得这样一个和式,但这个式子对他来说过于简单了,所以他把这个问题留给了你:

可以证明,结果可以写成,其中PQ互质,且。因此答案请以的形式输出,其中表示Q在模998244353下的逆元。

输入描述

输入包含一行两个数

输出描述

输出一行一个数,为求得的答案。

示例1

输入:

3 4

输出:

327

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 4145ms, 内存消耗: 179400K, 提交时间: 2020-10-05 18:44:33

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
#define mset(s,t) memset(s,t,sizeof(s))
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
const int N=10000005;
const int mod=998244353;
ll qpow(ll a,ll b=mod-2){
  ll res=1;
  a%=mod;
  while(b>0){
    if(b&1)res=res*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  return res;
}
const ll inv2=qpow(2);
const ll inv4=qpow(4);
const ll inv6=qpow(6);
const ll inv8=qpow(8);
const ll inv30=qpow(30);
int mu[N],g1[N],g2[N],g3[N];
bool vis[N];
int pr[N>>3],len,L=1e7;
void init(int n){
  mu[1]=1;
  for(register int i=2;i<=n;i++){
    if(!vis[i])pr[len++]=i,mu[i]=-1;
    for(register int j=0;j<len&&pr[j]*i<=n;j++){
      vis[pr[j]*i]=1;
      if(i%pr[j]==0)break;
      mu[pr[j]*i]=-mu[i];
    }
  }
  rep(i,1,n){
    g1[i]=(g1[i-1]+1ll*i*i%mod*i%mod*i%mod*mu[i])%mod;
    g2[i]=(g2[i-1]+1ll*i*i%mod*i%mod*mu[i])%mod;
    g3[i]=(g3[i-1]+1ll*i*i%mod*mu[i])%mod;
  }
}
ll S1(ll x){
  x%=mod;
  return x*(x+1)%mod*inv2%mod;
}
ll S2(ll x){
  x%=mod;
  return x*(x+1)%mod*(2*x+1)%mod*inv6%mod;
}
ll S3(ll x){
  x%=mod;
  return S1(x)*S1(x)%mod;
}
ll S4(ll x){
  x%=mod;
  return x*(x+1)%mod*(2*x+1)%mod*(3*x*x%mod+3*x-1)%mod*inv30%mod;
}
int n,m;

unordered_map<int,ll>Map1,Map2,Map3;
ll GG1(int n){
  if(n<=L)return g1[n];
  if(Map1[n])return Map1[n];
  ll ans=1;
  for(int i=2,j;i<=n;i=j+1){
    j=n/(n/i);
    ans=(ans-GG1(n/i)*(S4(j)-S4(i-1)+mod))%mod;
  }
  return Map1[n]=(ans%mod+mod)%mod;
}
ll GG2(ll n){
  if(n<=L)return g2[n];
  if(Map2[n])return Map2[n];
  ll ans=1;
  for(int i=2,j;i<=n;i=j+1){
    j=n/(n/i);
    ans=(ans-GG2(n/i)*(S3(j)-S3(i-1)+mod))%mod;
  }
  return Map2[n]=(ans%mod+mod)%mod;
}
ll GG3(ll n){
  if(n<=L)return g3[n];
  if(Map3[n])return Map3[n];
  ll ans=1;
  for(int i=2,j;i<=n;i=j+1){
    j=n/(n/i);
    ans=(ans-GG3(n/i)*(S2(j)-S2(i-1)+mod))%mod;
  }
  return Map3[n]=(ans%mod+mod)%mod;
}
unordered_map<int,ll>map4,map5,map6;
ll G1(int n){
  if(map4[n])return map4[n];
  ll ans=0;
  for(int i=1,j;i<=n;i=j+1){
    j=n/(n/i);
    ans=(ans+(GG1(j)-GG1(i-1)+mod)*S3(n/i))%mod;
  }
  return map4[n]=ans;
}
ll G2(int n){
  if(map5[n])return map5[n];
  ll ans=0;
  for(int i=1,j;i<=n;i=j+1){
    j=n/(n/i);
    ans=(ans+(GG2(j)-GG2(i-1)+mod)*S2(n/i))%mod;
  }
  return map5[n]=ans;
}
ll G3(int n){
  if(map6[n])return map6[n];
  ll ans=0;
  for(int i=1,j;i<=n;i=j+1){
    j=n/(n/i);
    ans=(ans+(GG3(j)-GG3(i-1)+mod)*S1(n/i))%mod;
  }
  return map6[n]=ans;
}
ll f1(){
  ll ans=0;
  for(int i=1,j;i<=n;i=j+1){
    j=min(n/(n/i),m/(m/i));
    ans=(ans+S2(n/i)*S2(m/i)%mod*(G1(j)-G1(i-1)+mod))%mod;
  }
  ans=ans*inv2%mod;
  ans=(ans+mod-S1(n)*S1(m)%mod*inv2%mod)%mod;
  return (ans+mod)%mod;
}
ll f4(){
  ll ans=0;
  for(int i=1,j;i<=n;i=j+1){
    j=min(n/(n/i),m/(m/i));
    ans=(ans+S2(n/i)*S2(m/i)%mod*(G1(j)-G1(i-1)+mod))%mod;
    ans=(ans-(S1(n/i)*S2(m/i)+S2(n/i)*S1(m/i))%mod*(G2(j)-G2(i-1)+mod))%mod;
    ans=(ans+S1(n/i)*S1(m/i)%mod*(G3(j)-G3(i-1)+mod))%mod;
  }
  ans=ans*inv4%mod;
  return (ans+mod)%mod;
}
int main(){
  init(L);
  //n=1e9,m=1e9;
  scanf("%d%d",&n,&m);
  if(n>m)swap(n,m);
  printf("%lld\n",2ll*(f1()+f4())%mod);
  return 0;
}

上一题