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 ...
随机推荐
- DES算法实现(C++版)
#include "memory.h" #include "stdio.h" enum {encrypt,decrypt};//ENCRYPT:加密,DECRY ...
- 最长公共子序列hdu1503
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1503 题意:给你两个字符串,把这两个字符串合并,使合并之后的字符串最短,并且合并之后的字符之间的相对位 ...
- 155. Min Stack (stack)
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- Python+Selenium学习--窗口切换及操作元素
场景 有时候我们在测试一个web 应用时会出现多个浏览器窗口的情况,在selenium1.0 中这个问题比较难处理.webdriver 提供了相关相方法可以很轻松的在多个窗口之间切换并操作不同窗口上的 ...
- stable
stable - 必应词典 美['steɪb(ə)l]英['steɪb(ə)l] n.马厩:马房:(养马作特定用途的)养马场 adj.稳定的:稳固的:牢固的:稳重的 v.使(马)入厩:把(马)拴在马厩 ...
- 【jquery】checkbox
jquery操作checkbox 模拟选中: $('#aaa').prop('checked', true); 模拟取消选中: $('#aaa').prop('checked', false); 其它 ...
- 分布式大数据多维数据分析(olap)引擎kylin[转]
Apache Kylin是一个开源的分布式分析引擎,提供Hadoop之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由eBay 开发并贡献至开源社区.它能在亚秒内查询巨大的Hiv ...
- java_13.1 javaAPI
1 API概念 API:是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件的以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节.2 String类的概念和不变性 Stri ...
- Swift 小技巧 || 老偏方
自己平时用的时候,或者看别人有一些好用的技巧分享一下,希望大家能get到 1.关于颜色 2.关于标记 // TODO:这样的标记XCode8才有的 // FIXME:这个也是XCode8有的
- ecplise自动提示失效,使用补全自动提示快捷键(Alt+/),但只显示“No Default Proposals”
在这里设置了自动提示,但是在使用的时候自动提示实现了.甚至使用补全自动提示快捷键(Alt+/),只显示“No Default Proposals”.今天在网上搜索了一下结果,主要有一下几种方法: 1. ...