Counting Divisors
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 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 :
(∑i=lrd(ik))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≤1012,r−l≤106,1≤k≤107) .
In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
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
这道没写出来,不过用质数求约数的个数,用了快速幂的方法
#include<iostream>
#include<map>
#include <cstdio>
#define mod 998244353
#define ll long long
using namespace std;
ll prime[100005]={2},P=1,N,Num;
map<ll,ll> divisor;
map<ll,ll>::iterator it;
ll isPrime(ll N){
if(N % 3==0) return N==3;
for(ll i=1;prime[i]*prime[i]<=N;++i)
if( N % prime[i]==0) return 0;
return 1;
}
ll divNum(ll Num){
for(ll i=0;prime[i]<=Num && i<P;++i)
while( Num % prime[i] == 0 ){
divisor[prime[i]]++;
Num /= prime[i];
}
if(Num!=1) divisor[Num]=1;
int result=1;
for(it=divisor.begin();it!=divisor.end();++it)
result *= (it->second + 1);
divisor.clear();
return result;
}
ll quickpow(ll a, ll b)
{
ll ans=1, base=a;
while(b!=0){
if(b&1!=0)
ans*=base%mod;
base*=base%mod;
b>>=1;
}
return ans%mod;
}
int main()
{
ll i;
for(i=3;i<=1000000;i+=2)
if(isPrime(i)) {
prime[P++]=i;
}
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
long long l, r, k;
scanf("%lld%lld%lld",&l,&r,&k);
long long cnt=0;
for(i=l;i<=r;i++)
{
//printf("%d",quickpow(i, k));
cnt += divNum(quickpow(i,k))%mod;
}
printf("%lld\n",cnt);
}