#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mem(i,a) memset(i,a,sizeof(i))
#define rson mid+1,r,rt<<1|1
#define lson l,mid,rt<<1
#define mp make_pair
#define pb push_back
#define ll long long
#define LL long long
using namespace std;
template <typename T>inline void read(T &_x_){
_x_=0;bool f=false;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=!f;ch=getchar();}
while ('0'<=ch&&ch<='9') {_x_=_x_*10+ch-'0';ch=getchar();}
if(f) _x_=-_x_;
}
const double eps = 1e-8;
const int maxn = 1e6+7;
const int mod = 998244353;
const ll inf = 1e15;
bool isPrime[maxn];
int prime[maxn];
void makePrime(){
isPrime[0] = isPrime[1] = false;
for (int i = 2; i < maxn; ++i)
isPrime[i] = true;
prime[0] = 0;
for (int i = 2; i < maxn; ++i) {
if (isPrime[i])
prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && i * prime[j] < maxn; ++j) {
isPrime[i * prime[j]] = false;
if (i % prime[j] == 0)
break;
}
}
}
int t;
ll l,r,k;
ll d[maxn],tmp[maxn];
int main(){
makePrime();
scanf("%d",&t);
while(t--){
read(l),read(r),read(k);
for(ll i=l;i<=r;i++) d[i-l]=1,tmp[i-l]=i;
for(int i=1;i<=prime[0];i++){
ll md=l%prime[i],j=l;
if(md){
j=prime[i]-md;
j+=l;
}
for(j;j<=r;j+=prime[i]){
ll tot=0;
while(tmp[j-l]%prime[i]==0){
tmp[j-l]/=prime[i];
tot++;
}
d[j-l]*=(tot*k+1);
d[j-l]%=mod;
}
}
ll ans=0;
for(ll i=l;i<=r;i++){
if(tmp[i-l]>1){
d[i-l]*=(k+1);
d[i-l]%=mod;
}
ans+=d[i-l];
ans%=mod;
}
printf("%I64d\n",ans);
}
return 0;
}
Counting Divisors
最新推荐文章于 2022-02-26 16:04:00 发布