多校的1003

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 :

(i=lrd(ik))mod998244353
Input
The first line of the input contains an integer  T(1T15) , denoting the number of test cases.

In each test case, there are  3  integers  l,r,k(1lr1012,rl106,1k107) .
 

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);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值