思路:对于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的更多相关文章

  1. hdu6069 Counting Divisors 晒区间素数

    /** 题目:hdu6069 Counting Divisors 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意:求[l,r]内所有数的k次方 ...

  2. 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 ...

  3. HDU 6069 Counting Divisors

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  4. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  5. DIVCNT2&&3 - Counting Divisors

    DIVCNT2 - Counting Divisors (square) DIVCNT3 - Counting Divisors (cube) 杜教筛 [学习笔记]杜教筛 (其实不算是杜教筛,类似杜教 ...

  6. hdu 6069 Counting Divisors 筛法

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  7. SPOJ 20713 DIVCNT2 - Counting Divisors (square)

    DIVCNT2 - Counting Divisors (square) #sub-linear #dirichlet-generating-function Let \sigma_0(n)σ​0​​ ...

  8. [SPOJ] DIVCNT2 - Counting Divisors (square) (平方的约数个数前缀和 容斥 卡常)

    题目 vjudge URL:Counting Divisors (square) Let σ0(n)\sigma_0(n)σ0​(n) be the number of positive diviso ...

  9. 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 ...

随机推荐

  1. Android笔记:Button

    示例代码摘自<第一行代码> ButtonDemo.java的代码: public class ButtonDemo extends Activity { @Override protect ...

  2. pta l3-7(天梯地图)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805051153825792 题意:给定n个地点,m条边以及边的 ...

  3. WdatePicker控件Javascript取得当前时间、取得减30分钟时间

    1.取得当前时间 function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var se ...

  4. 项目总结03:window.open()方法用于子窗口数据回调至父窗口,即子窗口操作父窗口

    window.open()方法用于子窗口数据回调至父窗口,即子窗口操作父窗口 项目中经常遇到一个业务逻辑:在A窗口中打开B窗口,在B窗口中操作完以后关闭B窗口,同时自动刷新A窗口(或局部更新A窗口)( ...

  5. 865. Smallest Subtree with all the Deepest Nodes 有最深节点的最小子树

    [抄题]: Given a binary tree rooted at root, the depth of each node is the shortest distance to the roo ...

  6. Wechat微信公众平台开发

    一.微信概述 1.历史背景 1)2011年1月21日,腾讯推出微信应用程序.(张小龙) 2)2012年8月20日,腾讯推出微信公众平台功能,同年11月开放第三方接口 3)2013年11月注册用户量突破 ...

  7. JFinal Web开发学习(三)前后台路由设计

    效果图: 一.写控制器 1.在controller包中新建AdminController后台控制器,继承Controller,实现一个index方法,作为的处理方法. /admin 后面,这个控制器中 ...

  8. linq join用法

    单条件: var query = from person in people join pet in pets on person equals pet.Owner select new { Owne ...

  9. MySQL 5.6.4 中TIMESTAMP with implicit DEFAULT value is deprecated 错误

    [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.   在免安装版mysql安装过程中出现:[Warning] TIMESTA ...

  10. php 多进程

    php 在使用场景中一般是处理web应用,所以多进程使用不适合在web中使用,且php-fpm中pcntl_fork不能使用,所以使用场景是在cgi模式下 一个进程调用pcntl_fork函数后,系统 ...