hdu6069 多校Counting Divisors
思路:对于n^k其实就是每个因子的个数乘了一个K。然后现在就变成了求每个数的每个质因子有多少个,但是比赛的时候只想到sqrt(n)的分解方法,总复杂度爆炸,就一直没过去,然后赛后看官方题解感觉好妙啊!通过类似素数筛法的方式,把L - R的质因子给分解,就可以在O(nlogn)的时间之内把所以的数给筛出来。
/* gyt
Live up to every day */ #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e6+;
const ll maxm = 1e7;
const ll mod = ;
const int INF = 0x3f3f3f;
const ll inf = 1e15 + ;
const db eps = 1e-;
int is[maxn], pri[maxn];
ll f[maxn], num[maxn];
int cnt;
ll r, l, k; void prim() {
cnt=;
memset(is, , sizeof(is));
memset(pri, , sizeof(pri));
for (int i=; i<maxn; i++) {
if (!is[i]) {
pri[++cnt]=i;
for (int j=i+i; j<maxn; j+=i) {
is[j]=;
}
}
}
}
void solve() {
scanf("%lld%lld%lld", &l, &r, &k);
for (ll i=l; i<=r; i++) {
f[i-l+]=, num[i-l+]=i;
}
for (int i=; i<=cnt; i++) {
ll be=l+pri[i]-l%pri[i];
if (l%pri[i]==) be=l;
for (ll j=be; j<=r; j+=pri[i]) {
ll sum=;
while (num[j-l+]%pri[i]==) {
sum++;
num[j-l+]/=pri[i];
}
f[j-l+]=f[j-l+]*(k*sum%mod+)%mod;
}
}
ll ans=;
for (ll i=l; i<=r; i++) {
if (num[i-l+]!=) f[i-l+]=f[i-l+]*(k+)%mod;
ans=(ans+f[i-l+])%mod;
}
cout<<ans<<endl;
}
int main() {
int t = ;
//freopen("in.txt", "r", stdin);
scanf("%d", &t);
prim();
while(t--)
solve();
return ;
}
解释:
for (ll i=l; i<=r; i++) {
f[i-l+]=, num[i-l+]=i;
}
如果不进行这一步,那么数是1~1^12存不下,但是我们已知r-l<=1e6,这样就可以存下了。
f[i]表示当前的因数个数,num[i],从l到r(下标1-(r-l+1))的数。
for (ll i=l; i<=r; i++) {
if (num[i-l+]!=) f[i-l+]=f[i-l+]*(k+)%mod;
ans=(ans+f[i-l+])%mod;
}
判断当前这个数还有没有素数因子。
hdu6069 多校Counting Divisors的更多相关文章
- hdu6069 Counting Divisors 晒区间素数
/** 题目:hdu6069 Counting Divisors 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意:求[l,r]内所有数的k次方 ...
- 2017 Multi-University Training Contest - Team 4 hdu6069 Counting Divisors
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6069 题目: Counting Divisors Time Limit: 10000/5000 ...
- HDU 6069 Counting Divisors
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- hdu 6069 Counting Divisors(求因子的个数)
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- DIVCNT2&&3 - Counting Divisors
DIVCNT2 - Counting Divisors (square) DIVCNT3 - Counting Divisors (cube) 杜教筛 [学习笔记]杜教筛 (其实不算是杜教筛,类似杜教 ...
- hdu 6069 Counting Divisors 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- SPOJ 20713 DIVCNT2 - Counting Divisors (square)
DIVCNT2 - Counting Divisors (square) #sub-linear #dirichlet-generating-function Let \sigma_0(n)σ0 ...
- [SPOJ] DIVCNT2 - Counting Divisors (square) (平方的约数个数前缀和 容斥 卡常)
题目 vjudge URL:Counting Divisors (square) Let σ0(n)\sigma_0(n)σ0(n) be the number of positive diviso ...
- 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 ...
随机推荐
- overflow属性的用法
<style type="text/css">div{ background-color:#00FFFF; width:150px; height:150px; ove ...
- with as 如何工作
with as 如何工作 with如何工作? Python对with的处理还是很机智滴.基本思想就是with所求值的对象必须有一个__enter__()方法,一个__exit__()方法 紧跟wi ...
- POJ3259 :Wormholes(SPFA判负环)
POJ3259 :Wormholes 时间限制:2000MS 内存限制:65536KByte 64位IO格式:%I64d & %I64u 描述 While exploring his many ...
- 155. Min Stack (stack)
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- 154. Find Minimum in Rotated Sorted Array II (Array; Divide-and-Conquer)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- 20 【python】入门指南:常用数据结构
Python内置了三种高级数据结构:list,tuple,dict list:数组,相同类型的元素组成的数组 tuple:元组,相同类型的元素组成的数组,但是这里有限定条件(长度是固定的,并且值也是固 ...
- [LeetCode_94] Binary Tree Inorder Traversal
题目链接 https://leetcode.com/problems/binary-tree-inorder-traversal/ 题意 二叉树的中序遍历 思路 中序遍历:即"左中右&quo ...
- python之格式化输出
字符串格式化有两种方式,%和format 先介绍下%号的方法 #%s的语法结构,叫做占位符,就是先占一个位置,然后我们用真实的要显示的数据替换占位符即可#最简单的用法就是下面的方式,其实%s还有其他的 ...
- 662. Maximum Width of Binary Tree二叉树的最大宽度
[抄题]: Given a binary tree, write a function to get the maximum width of the given tree. The width of ...
- ATM取款机系统代码及此次作业感受
本次乃我们软件工程专业开学第一个小测试,本来以为是和之前2016级相同的或者类似得软件,所以之前学了好久的那个程序完全失去了它的作用,当然了老师也从来没有按套路出过牌,所以这个下马威我觉得作用起到了. ...