题意:
求
(∑i=lrd(ik))mod998244353
思路:
PS:两次筛法,第一次筛出所有的素数,第二次用素数去筛区间[L,R]之间的数,然后求出他们对应的值,当处理完之后f[i]>1的话说明是素数。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef set<int>::iterator ITER;
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define clr(x,y) memset(x,y,sizeof x)
const int maxn = 1e6 + 10;
const int Mod = 998244353;
const int N = 2;
struct Matrix{Matrix(){clr(m,0);}int m[N][N];};
Matrix Mul(Matrix a,Matrix b){Matrix c;for(int i = 0; i < N; i ++){for(int k = 0; k < N; k ++){if(a.m[i][k] == 0)continue;for(int j = 0; j < N; j ++)c.m[i][j] += a.m[i][k] * b.m[k][j] % Mod,c.m[i][j] %= Mod;}}return c;}
ll Mul(ll a,ll b){a %= Mod;b %= Mod;ll ret = 0;while(b){if(b & 1){ret += a;if(ret > Mod)ret -= Mod;}b >>= 1;a = (a << 1) % Mod;}return ret;}
Matrix pows(Matrix x,ll n){Matrix ret;for(int i = 0; i < 2; i ++)ret.m[i][i] = 1;while(n){if(n & 1)ret = Mul(ret,x);x = Mul(x,x);n >>= 1;}return ret;}
ll pows(ll x,ll n){ll ret = 1;while(n){if(n & 1)ret = ret * x % Mod;x = x * x % Mod;n >>= 1;}return ret;}
ll powss(ll x,ll n){ll ret = 1;while(n){if(n & 1)ret = Mul(ret,x);x = Mul(x,x);n >>= 1;}return ret;}
ll gcd(ll x,ll y){return y ? gcd(y,x % y):x;}
ll lcm(ll x,ll y){return x /gcd(x,y) * y;}
ll euler(int n){int ret = n;for(int i = 2; i * i<= n; i ++)if(n % i == 0){ret = ret / i * (i - 1);while(n % i == 0)n /= i;}if(n > 1)ret = ret / n * (n - 1);return ret;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d = a;x = 1;y = 0;return;}ex_gcd(b,a % b,d ,y,x);y -=a/b * x;}
inline int lowbit(int x){return x &(-x);}
//void update(int x,int val){for(int i = x; x < maxn; i += lowbit(i))tree[i] += val;}
//void get(int x){int ret = 0;for(int i = x; i > 0 ;i -= lowbit(i))ret += tree[i];return ret;}
//int finds(int x){return fa[x] == x ? x : (fa[x] = finds(fa[x]));}
bool is_[maxn];
ll prime[maxn];
int len;
ll f[maxn],g[maxn];
ll l,r,k;
void Init()
{
len = 0;
clr(is_,true);
for(int i = 2; i < maxn; i ++)
{
if(is_[i])
{
prime[len ++] = i;
for(int j = i * 2; j < maxn; j += i)
is_[j] = false;
}
}
}
void fun(int p)
{
for(ll i = l/p * p; i <= r; i += p)
if(i >= l)
{
// cout << p << " -> " << i << endl;
int cnt = 0;while(f[i - l] % p == 0)cnt ++,f[i - l] /= p;
g[i - l] = g[i - l] * (cnt * k + 1) % Mod;
}
}
int main()
{
Init();
int Tcase;
scanf("%d",&Tcase);
for(int ii = 1; ii <= Tcase; ii ++)
{
scanf("%I64d%I64d%I64d",&l,&r,&k);
ll n = r - l;
for(int i = 0; i <= n; i ++)f[i] = i + l,g[i] = 1;
for(int i = 0; i < len;i ++)
{
if(prime[i] * prime[i] > r)break;
fun(prime[i]);
}
ll ans = 0;
for(int i = 0; i <= n; i ++)
{
if(f[i] > 1)g[i] = g[i] * (k + 1) % Mod;
// cout << i + l<< " " << g[i] << endl;
ans = (ans + g[i]) % Mod;
}
printf("%I64d\n",ans);
}
return 0;
}