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 ...
随机推荐
- HDU-1176.免费馅饼(数字三角形变形)
看到网上大多都是逆向的总结,我来搞个正向的吧... 这道题想着是和数字三角形差不多的,但是最后愣是没有写出来,感受到一股菜意......哭唧唧.jpg 本题大意: 给定n个序列,每个序列包含两个数表示 ...
- TOJ3112: 单词串串烧(回溯)
传送门(<--可以点击的) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 “单词串串烧”是一款拼词智力游戏,给定4*4的方格,随机取16个 ...
- [codeforces_597B] Restaurant(贪心)
题目链接 http://codeforces.com/problemset/problem/597/B 题意 输入:区间数目n.及n个区间的起止(左闭右闭). 输出:最多不重叠的区间有多少个. 思路 ...
- c#: 以模态窗口显示于其它进程窗体之前
产品之工具箱,需要工具以模态窗体,显示于主界面之上.记下代码点,以做备忘. 1.IWin32Window internal class Win32Window : IWin32Window { pub ...
- swift - 封装百度地图
1. #import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件 #import <BaiduMapAPI_Map/B ...
- 线特征---LSD and LBD程序运行(一)
最近在看有关特征提取的线特征,暑期就看了相关的论文:<基于点线综合特征的双目视觉SLAM方法_谢晓佳>,最近呢,把里面有关线特征提取LSD和描述子LBD的代码跑了一遍,记录如下: [1]L ...
- CSS 图片居中
} .left-logo a { height: 100px; width: 55px; display: block; } .left-logo a img{ height: ; width: 55 ...
- python 3.6.5 hashlib 和 hmac 模块
import hashlib m=hashlib.md5()# m=hashlib.sha256() m.update('hello'.encode('utf8'))print(m.hexdigest ...
- css代码插入三种方式
1.内联式 <p style="color:red;font-size: 12px">iutt</p> 2.嵌入式 <style type=" ...
- 1、javaweb学习之配置文件web.xml
今天这里主要讲述javaweb中的配置文件web.xml中的内容及其作用,都是基础部分,对于初学者需要好好掌握理解. 简单配置: <servlet> <servlet-name ...