Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 3041    Accepted Submission(s): 1130

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
 
思路:先将1000005以内的素数打表(素数筛法O(n)),然后将每个数拆成S=p1^a1*p2*^a2...*pn^an 的形式则 d(S)=(1+a1)*(1+a2)....*(1+an);
实现方法:用num[] 存下当前拆分后剩下的数字,用ans[i]存下第i个数字此时的已拆分的累乘结果,将素数从小到大扫一遍,对[l,r]每个数字进行拆分,逐一更新ans[i]的值
代码:
#include<bits/stdc++.h>

typedef long long ll;
using  namespace std;

;
const int inf=1e9;
;

ll l,r,k;
bool v[N];
ll ans[N];
ll num[N];
int pri[N];
int pcnt;
void init()
{
    pcnt = ;//素数筛
    ; i <= N; i++)
    {
        if(!v[i])
            pri[pcnt++] = i;
        ; j < pcnt && pri[j] <= N/i; j++)
        {
            v[i*pri[j]] = ;
            ) break;
        }
    }
}
void f()
{
    for(ll i=l;i<=r;i++)//初始化记录数组
        num[i-l]=i,ans[i-l]=;
}
int main()
{
    int t;
    init();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld%lld",&l,&r,&k);
        f();
        ;i<pcnt&&pri[i]<=;i++){//限制质因子大小
            ll p=pri[i];
            ll d=l/p+(l%p>);
            ) d=;
            for(ll j=d*p;j<=r;j+=p){
                ll cnt=;
                ){
                    num[j-l]/=p;
                    cnt++;
                }
                ans[j-l]=(ans[j-l]%mod)*((+k*cnt)%mod)%mod;
            }
        }
        ll sum=;
        for(ll i=l;i<=r;i++){
            )//还存在一个大于1000000的因子,再乘上k+1
                sum=(sum+ans[i-l]*(k+))%mod;
            else
                sum=(sum+ans[i-l])%mod;
        }
        printf("%lld\n",sum);
    }

}
 

HDOJ 6069 素数筛法(数学)的更多相关文章

  1. hdu6069(简单数学+区间素数筛法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 给出 l, r, k.求:(lambda d(i^k))mod998244353,其中 ...

  2. 数学#素数筛法 HDU 4548&POJ 2689

    找素数本来是很简单的问题,但当数据变大时,用朴素思想来找素数想必是会超时的,所以用素数筛法. 素数筛法 打表伪代码(用prime数组保存区间内的所有素数): void isPrime() vis[]数 ...

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

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

  4. NowCoder猜想(素数筛法+位压缩)

    在期末被各科的大作业碾压快要窒息之际,百忙之中抽空上牛客网逛了逛,无意中发现一道好题,NowCoder猜想,题意很明显,就是个简单的素数筛法,但竟然超内存了,我晕(+﹏+)~  明明有 3 万多 k ...

  5. [原]素数筛法【Sieve Of Eratosthenes + Sieve Of Euler】

    拖了有段时间,今天来总结下两个常用的素数筛法: 1.sieve of Eratosthenes[埃氏筛法] 这是最简单朴素的素数筛法了,根据wikipedia,时间复杂度为 ,空间复杂度为O(n). ...

  6. POJ 3292 Semi-prime H-numbers (素数筛法变形)

    题意:题目比较容易混淆,要搞清楚一点,这里面所有的定义都是在4×k+1(k>=0)这个封闭的集合而言的,不要跟我们常用的自然数集混淆. 题目要求我们计算 H-semi-primes, H-sem ...

  7. 素数筛法—时间复杂度O(n)

    请你想出一个算法求出n以内(含n)的所有素数,要求算法的时间复杂度越小越好. 这里介绍一种算法——快速线性素数筛法(欧拉筛法),时间复杂度O(n). 诀窍在于:筛除合数时,保证每个合数只会被它的最小质 ...

  8. hdu-2136 Largest prime factor---巧用素数筛法

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2136 题目大意: 每个素数在素数表中都有一个序号,设1的序号为0,则2的序号为1,3的序号为2,5的 ...

  9. UVa 294 - Divisors 解题报告 c语言实现 素数筛法

    1.题目大意: 输入两个整数L.H其中($1≤L≤H≤10^9,H−L≤10000$),统计[L,H]区间上正约数最多的那个数P(如有多个,取最小值)以及P的正约数的个数D. 2.原理: 对于任意的一 ...

随机推荐

  1. Testlink安装步骤Checking if C:\inetpub\wwwroot\testlink-1.9.3\gui\templates_c directory is writable Failed !

    Testlink安装过程中问题现象: Checking if C:\inetpub\wwwroot\testlink-1.9.3\gui\templates_c directory is writab ...

  2. jquery删除表格行

    $(".mingxirmspan").click(function(){ $(this).closest("tr").remove(); })

  3. [leetcode-560-Subarray Sum Equals K]

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  4. 从.src.rpm包中提取出完整的源码的方法

    1 什么是完整的源码 就是说,最初始的源码加上打了所有的patch后的源码,即最新的源码. 2 过程 2.1 从.src.rpm中提取完整的rpm工程文件 2.1.1 rpm to cpio rpm2 ...

  5. Error creating document instance

    Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 52; columnNumbe ...

  6. OpenGL的配置与搭建

    一.项目中所使用的OpenGL扩展库有: 1. freeglut-3.0.0 2. glew-2.0.0 3. glm-0.9.7.3 二.添加扩展库文件 在工程项目文件夹里面添加OpenGLExte ...

  7. voa 2015.4.29

    Nepal has declared three days of mourning for the victims of Saturday's 7.8 magnitude earthquake tha ...

  8. Unreal Engine 4 Radiant UI 插件入门(三)——从蓝图中调用JS

    不知道大家有没有混淆.这篇教程说的是从蓝图中调用JS的功能(以改变H5内的内容). 在安装了UE4和RadiantUI的前提下学习这篇教程.本篇教程接着上一篇教程,建议请先看上一篇. 第一步:在网页中 ...

  9. 代码托管SVN到Git迁移(使用小乌龟工具)

    1.环境信息 Git   Server     华为软件开发云   代码托管 SVN Server    本地SVN服务器   Windows Server2012 R2 本地主机       Win ...

  10. 在Jekyll博客添加评论系统:gitment篇

    最近在Github Pages上使用Jekyll搭建了个人博客( jacobpan3g.github.io/cn ), 当需要添加评论系统时,找了一下国内的几个第三方评论系统,如"多说&qu ...