hdu 6069 Counting divisors 公式+区间筛】的更多相关文章

比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p​m​^c​m​​​​,则d(n^k)=(k*c1+1)(k*c2+1)...(k*cm+1)d(n​k​​)=(kc​1​​+1)(kc​2​​+1)...(kc​m​​+1).然后由于l,r的值很大,但是l-r的范围还是可以接受的,所以我们用一个偏移数组 来存l<=n<=r数的d(n).然后就…
题目链接 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 followin…
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K 然后现在就变成了求每个数的每个质因子有多少个,但是比赛的时候只想到sqrt(n)的分解方法,总复杂度爆炸,就一直没过去,然后赛后看官方题解感觉好妙啊! 通过类似素数筛法的方式,把L - R的质因子给分解,就可以在O(nlogn)的时间之内把所以的数给筛出来. 代码: /** @xigua */ #i…
Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1604    Accepted Submission(s): 592 Problem Description In mathematics, the function d(n) denotes the number of divisors of p…
Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 2599    Accepted Submission(s): 959 Problem Description In mathematics, the function d(n) denotes the number of divisors of p…
Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 3170    Accepted Submission(s): 1184 Problem Description In mathematics, the function d(n) denotes the number of divisors of…
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,…
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{m}}^{pm}$,那么n的因子数就是 n的k次方也是一样的,也就是p前面乘个k就可以了. 先打个1e6范围的素数表,然后枚举每个素数,在[ l , r ]寻找该素数的倍数,将其分解质因数. 到最后如果一个数没有变成1,那就说明这个数是大于1e6的质数.(它就只有0和1两种选择) #include<…
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选,n = p1^c1*p2^c2*....*pn^cn,那么 d(n) = (c1+1) * (c2+1) * ...*(cn+1). d(n^k) =  (kc1+1) * (kc2+1) * ...*(kcn+1),这样的话,我们只要求出每个数的素因子的个数就好,直接算还是不行,只能先把1-sqrt(n)之…
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     题意:就是那个公式 感觉还是题解讲的清楚 #include<iostream> #include<cstdio> #include<cstdlib> #i…
/** 题目:hdu6069 Counting Divisors 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意:求[l,r]内所有数的k次方的约数个数之和. 思路: 用(1+e1)*(1+e2)*...*(1+en)的公式计算约数个数. 素数筛出[l,r]内的素因子,然后直接计算结果.(一开始我用vector存起来,之后再处理,结果超时, 时间卡的很紧的时候,vector也会很占用时间.) */ #include<iostream>…
题面 洛谷 \(\sigma_0(i)\) 表示\(i\) 的约数个数 求\(S_k(n)=\sum_{i=1}^n\sigma_0(i^k)\mod 2^{64}\) 多测,\(T\le10^4,n,k\le10^{10}\) 题解 令\(f(i)=\sigma_0(i^k)\)首先可以发现几个性质 \[f(1)=1\] \[f(p)=k+1\] \[f(p^c)=kc+1\] \[f(ab)=f(a)f(b),\gcd(a,b)=1\] 也就是说\(f\)是个积性函数,直接上\(Min\_2…
传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的优先排序,注意是所有的线段 :(这里是将线段都去掉只保留两个端点) 然后从左到右的顺序经行扫描,遇到横的线段,如果是左端点对应的 yi 便++ , 若是右端点对应的y1便--:  遇到竖直的线段,便统计区间[y1,y2] 的数 , 看到这了是不是有点东西了呢? 如果我是按照x排序的话,两线段若想相交…
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6069 题目: Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1235    Accepted Submission(s): 433 Problem Description In mathem…
题目 vjudge URL:Counting Divisors (square) Let σ0(n)\sigma_0(n)σ0​(n) be the number of positive divisors of nnn. For example, σ0(1)=1\sigma_0(1) = 1σ0​(1)=1, σ0(2)=2\sigma_0(2) = 2σ0​(2)=2 and σ0(6)=4\sigma_0(6) = 4σ0​(6)=4. Let S2(n)=∑i=1nσ0(i2).S_2(n…
DIVCNT2 - Counting Divisors (square) DIVCNT3 - Counting Divisors (cube) 杜教筛 [学习笔记]杜教筛 (其实不算是杜教筛,类似杜教筛的复杂度分析而已) 你要大力推式子: 把约数个数代换了 把2^质因子个数 代换了 构造出卷积,然后大于n^(2/3)还要搞出约数个数的式子和无完全平方数的个数的容斥... .... 然后恭喜你,spoj上过不去... bzoj能过: #include<bits/stdc++.h> #define…
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生交点,所以先对横向线段按x端点排序,每次加入一个线段,将其对应的y坐标位置+1,当出现一个竖向线段时,查询它的两个y端点之间的和即为交点个数. 注意点:对x坐标排序是对所有线段端点排序:因为可能出现 “  1-1  “ 这样的情况,所以对于横着的线段,需要进行首尾x坐标处理:我的方法是对于x坐标,先…
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarant…
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…
Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2496    Accepted Submission(s): 788 Problem Description Today is the 10th Annual of “September 11 attacks”, the Al Qaeda is about to attack…
No Pain No Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2000    Accepted Submission(s): 851 Problem Description Life is a game,and you lose it,so you suicide. But you can not kill yours…
Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1959    Accepted Submission(s): 1006 Problem Description There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i…
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C,D)\) && \(E=(AB,BC,CD,DA,AC)\) 显然\(A-structure\)是由两个有公共边的三元环构成的 \(1 <=n <= 1e5\) \(1 <= m <= min(2e5,n*(n-1)/2)\) 思路: 三元环计数 做法1. ①统计每个点…
DIVCNT2 - Counting Divisors (square) #sub-linear #dirichlet-generating-function Let \sigma_0(n)σ​0​​(n) be the number of positive divisors of nn. For example, \sigma_0(1) = 1σ​0​​(1)=1, \sigma_0(2) = 2σ​0​​(2)=2 and \sigma_0(6) = 4σ​0​​(6)=4. LetS_2(…
给[L,R]区间的每一个数都质因数分解的复杂度可以达到(R-L)logR,真的涨姿势…… 另外,质因数分解有很重要的一点,就是只需要打sqrt(R)以内的素数表就够了……因为超过sqrt(R)的至多只有一个,分解其他的那些剩下的就是了. 果然学习的过程中要精益求精,把时间和空间都尽量降到最低. 此外还有一个很重要的公式.d(i)表示i的因子个数.那么 #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ];…
http://acm.hdu.edu.cn/showproblem.php?pid=6069 [题意] 给定l,r,k,求 d(n)是n的因子个数 [思路] [Accepted] #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> #include<queue>…
设n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p​1​c​1​​​​p​2​c​2​​​​...p​m​c​m​​​​,则d(n^k)=(kc_1+1)(kc_2+1)...(kc_m+1)d(n​k​​)=(kc​1​​+1)(kc​2​​+1)...(kc​m​​+1). 枚举不超过\sqrt{r}√​r​​​的所有质数pp,再枚举区间[l,r][l,r]中所有pp的倍数,将其分解质因数,最后剩下的部分就是超过\sqrt{r}√​r​​​的质数,只可能是00个或11个…
题意 计算\(\sum_{i=l}^kd(i^k)(d_i代表i的因子数)\) 分析 比赛搞了3个小时都没搞出来,有两个思维上的trick 1.要先遍历素数,再遍历[L,R],而不是枚举每个数,然后对每个数进行质因数分解 2.比赛的时候我有想过枚举素数,但是忘记因子计算公式可以分开相乘,而不用一次性求粗来,导致我们队的崩盘,我要背锅!!! 具体的做法:枚举每个素数,并枚举[L,R]中的素数的倍数,对于每个倍数,统计因子个数,用b[i]代表第i个数的因子数,具体键代码 #include <bits…
分析 首先,STO ywy OTZ,ywy TQL%%%! 说一下这道题用min_25筛怎么做. 容易发现,对于所有质数\(p\),都满足\(f(p)=4\),于是我们就可以直接通过\([1,x]\)内的质数的个数\(h(x)\)来求出\(g(x)=\sum_{i=1}^{x}f(i) \times [i \in prime]\)了,即\(g(x)\)可以等价地表示为\(g(x)=4 \times h(x)\).如何求\(h(x)\)是min_25筛的基本操作就不过多赘述了.而且进一步分析我们可…
d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; #define MOD 998244353ll #define MAXP 1000100 typedef long long ll; ll x,y; int T,K; bool isNotPrime[MAXP+10]; int num_prime,prime[MAXP+10]; void shai() { f…