Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

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(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).

 
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
 
Source

官方题解:

  唯一分解定理

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define bug(x) cout<<"bug"<<x<<endl; const int N=1e5+,M=1e6+,inf=;
const LL INF=1e18+,mod=; const int MAXN=;
int prime[MAXN];//保存素数
bool vis[MAXN];//初始化
int Prime(int n)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
if(!vis[i])
prime[cnt++]=i;
for(int j=; j<cnt&&i*prime[j]<n; j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
return cnt;
} LL num[M],ans[M]; int main()
{
int cnt=Prime();
int T;
scanf("%d",&T);
while(T--)
{
for(int i=; i<; i++)
num[i]=,ans[i]=;
LL l,r,K;
scanf("%lld%lld%lld",&l,&r,&K);
for(int q=; q<cnt; q++)
{
int i=prime[q];
LL L=(l%i==?l:(l/i+)*i);
for(LL j=L; j<=r; j+=i)
{
LL temp=j,base=;
int x=;
while(temp%i==)
{
x++;
temp/=i;
base*=i;
}
ans[j-l+]*=(1LL*K*x+)%mod;
ans[j-l+]%=mod;
num[j-l+]*=base;
}
}
for(LL i=l; i<=r; i++)
{
if(num[i-l+]!=i)
ans[i-l+]*=K+,ans[i-l+]%=mod;
}
LL out=;
for(LL i=l;i<=r;i++)
out+=ans[i-l+],out%=mod;
printf("%lld\n",out);
}
return ;
}

hdu 6069 Counting Divisors 筛法的更多相关文章

  1. HDU 6069 Counting Divisors —— 2017 Multi-University Training 4

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  2. HDU 6069 Counting Divisors

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  3. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  4. HDU 6069 Counting Divisors(区间素数筛法)

    题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...

  5. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...

  6. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

  7. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  8. hdu 6069 Counting divisors 公式+区间筛

    比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p ...

  9. HDU 6069 Counting Divisors(2017 Multi-University Training Contest - Team 4 )

    Output For each test case, print a single line containing an integer, denoting the answer.   Sample ...

随机推荐

  1. AtCoder Beginner Contest 044 B - 美しい文字列 / Beautiful Strings

    Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Let w be a string cons ...

  2. ltp-ddt的makefile结构

    顶层makefile COMMON_TARGETS        := pan utils COMMON_TARGETS    += tools testcases/ddt COMMON_TARGET ...

  3. MSVCR120.dll 解决

    https://www.microsoft.com/en-us/download/details.aspx?id=40784 装之 from : https://answers.microsoft.c ...

  4. Django里自定义用户登陆及登陆后跳转到登陆前页面的实现

    def logout(request): request.session.flush() return HttpResponseRedirect(request.META.get('HTTP_REFE ...

  5. 忘记MySQL root密码,如何不重启修改

    说个前提:mysqld可以处理kill命令发送的信号,如SIGHUP.SIGTERM,SIGHUP信号产生的行为类似于flush命令. 不重启找回root密码首先需要有个较低权限的账号,比如可以修改t ...

  6. Spring Boot 2(一):Spring Boot 2.0新特性

    Spring Boot 2(一):Spring Boot 2.0新特性 Spring Boot依赖于Spring,而Spring Cloud又依赖于Spring Boot,因此Spring Boot2 ...

  7. 使用 select 实现 goroutine 超时

    虽然携程是Go语言中一个新的概念,嗯,但它本质上依然是属于多线程.超时机制是多线程中是一个非常重要的保障程序的鲁棒性的一个措施:错误是很难预估的,在多线程中更为显著,更容易出现难以预料的错误. 一个异 ...

  8. face_recognition 基础接口

    face_recognition 基础接口 face_recognition使用世界上最简单的人脸识别库,在Python或命令行中识别和操作人脸. 使用dlib最先进的人脸识别技术构建而成,并具有深度 ...

  9. 面试必问:Spring循环依赖的三种方式

    引言:循环依赖就是N个类中循环嵌套引用,如果在日常开发中我们用new 对象的方式发生这种循环依赖的话程序会在运行时一直循环调用,直至内存溢出报错.下面说一下Spring是如果解决循环依赖的. 第一种: ...

  10. Android开发发布真机调试

    使用真机测试原因: 1. 模拟器启动慢,真机测试速度较快 2. 有些程序在真机测试才有效,模拟器存在bug,结果要以真机为标准 连接方法: 1.设置手机为开发者模式(设置->关于手机->连 ...