Problem Description
In mathematics, the function
d(n)
denotes the number of divisors of positive integer
n
.
For example, d(12)=6
because
1,2,3,4,6,12
are all
12
's divisors.
In this problem, given l,r
and
k
, your task is to calculate the following thing :
For example, d(12)=6
In this problem, given l,r
(∑
i=l
r
d(i
k
))mod998244353![]()
![]()
Input
The first line of the input contains an integer
T(1≤T≤15)
, denoting the number of test cases.
In each test case, there are 3
integers
l,r,k(1≤l≤r≤10
12
,r−l≤10
6
,1≤k≤10
7
)
.
In each test case, there are 3
Output
For each test case, print a single line containing an integer, denoting the answer.
Sample Input
3 1 5 1 1 10 2 1 100 3
Sample Output
10 48 2302解题思路:http://www.7zhang.com/index/cms/read/id/429127.html#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; int prime[1000005]; ll f[1000005],num[1000005],p[1000005]; ll mod=998244353; ll MAXN=1e6+5; int cnt; int main() { memset(prime, 0, sizeof(prime)); cnt = 0; prime[1] = 1; for(ll i=2; i<1000005; i++) { if(!prime[i]) { p[cnt++] = i; for(ll j=i*i; j<MAXN; j+=i) prime[j] = 1; } } int T; scanf("%d",&T); while(T--) { ll l,r,k; scanf("%lld%lld%lld",&l,&r,&k); ll ans=0; if(l==1) {ans++;l++;} for(int i=0;i<=r-l;i++) { f[i]=i+l; num[i]=1; } for(int i=0;i<cnt&&p[i]*p[i]<=r;i++) { ll tmp=l; if(l%p[i]!=0) tmp=(l/p[i]+1)*p[i];//离l最近的含有p[i]因子的数 for(ll j=tmp;j<=r;j+=p[i]) { ll flag=0; while(f[j-l]%p[i]==0) { flag++; f[j-l]/=p[i]; } num[j-l]=num[j-l]*(flag*k+1)%mod; } } for(int i=0;i<=r-l;i++) { if(f[i]==1) ans=(ans+num[i])%mod; else ans=(ans+num[i]*(k+1)%mod)%mod; } printf("%lld\n",ans); } return 0; } k点击打开链接

本文介绍了一个数学问题,即计算在给定范围内正整数n的除数个数d(n)的累加,并对结果取模。该问题通过筛选素数并利用素数分解的方法解决,给出了一段C++代码实现。
586

被折叠的 条评论
为什么被折叠?



