[HDU]6069 Counting Divisors
求:
題解:
設
時間複雜度
#include<stdio.h>
#define it (pos - l)
typedef long long LL;
const int MOD = 998244353;
const int MAXN = 1e6 + 500;
const int o = 1000000;
int p[MAXN], prm[MAXN], sz;
LL arr[o + 10], d[o + 10];
void init() {
for(int i = 2; i < MAXN; ++i) {
if(!p[i]) prm[sz++] = i;
for(int j = 0; j < sz; ++j) {
int t = i * prm[j];
if(t >= MAXN) break ;
p[t] = true;
if(i%prm[j] == 0) break;
}
}
}
LL work(LL l, LL r, LL k) {
for(int i = 0; i < sz; ++i) {
LL pos = (l + prm[i] - 1) / prm[i] * prm[i];
while(pos <= r) {
LL cnt = 0;
while(arr[it] % prm[i] == 0) {
++cnt;
arr[it] /= prm[i];
}
d[it] *= cnt * k + 1;
d[it] %= MOD;
pos += prm[i];
}
}
LL res = 0;
for(LL pos = l; pos <= r; ++pos) {
// printf("#%lld\n", d[it]);
if(arr[it] == 1) {
res += d[it];
} else {
res += d[it] * (k +1);
}
res %= MOD;
}
return res;
}
int main()
{
init();
int T;
LL l, r, k;
scanf("%d", &T);
while(T--) {
scanf("%lld%lld%lld", &l, &r, &k);
for(LL pos = l; pos <= r; ++pos) {
d[it] = 1;
arr[it] = pos;
}
LL ans = work(l, r, k);
printf("%lld\n", ans);
}
return 0;
}
相關推薦
[HDU]6069 Counting Divisors
求: (∑i=lrd(ik))mod998244353 l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) 題解: 設n=pc11pc22...pcmmn=p,則d(nk)=
hdu--6069--Counting Divisors
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int mod = 998244353;const int maxn = 1000009;bool Isprime[maxn]; ///素數表1
Hdu 6069 Counting Divisors【素數區間篩+預處理素因子分解】
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 3150 Ac
HDU 5952 Counting Cliques(dfs)
lap ont there ins -- icpc output stream script Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja
hdu6069 多校Counting Divisors
urn def ever http 16px += () 判斷 ons 思路:對於n^k其實就是每個因子的個數乘了一個K。然後現在就變成了求每個數的每個質因子有多少個,但是比賽的時候只想到sqrt(n)的分解方法,總復雜度爆炸,就一直沒過去,然後賽後看官方題解感
HDU 3887 Counting Offspring(DFS序)
pac ria div cst key rst n-1 include http Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java
HDU 6184 Counting Stars 經典三元環計數
long mes div amp lld algorithm light 無向圖 nbsp 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 題意: n個點m條邊的無向圖,問有多少個A-structure 其中A-str
HDU 1264 Counting Squares(Hash)或者(線段樹+線掃描)
bsp pan 解決 printf 就是 大小 lag 線段 ash http://acm.hdu.edu.cn/showproblem.php?pid=1264 題意:給你矩形的左下角和右上角兩個坐標,讓你求這些矩形覆蓋的面積的大小!~ 分析:一看就是線段樹+線掃描的問題
HDU - 5952 Counting Cliques (dfs)
-- wap open col set cst play bsp sca 題目鏈接: Counting Cliques 題意:一個有N個點M條邊的圖,球其中由S個點構成的團的個數。一個團是一個完全子圖。 題解:拿到這題想了好久。。沒想到dfs就完事了。就dfs一下,回溯一下
HDU 6184 Counting Stars
push space mage sta vector html 代碼 false inf Counting Stars http://acm.hdu.edu.cn/showproblem.php?pid=6184 題意:求這樣圖形的個數。 分析: 三元環計數
HDU - 5952 Counting Cliques(DFS)
maximum you memset dfs ons let iostream 記錄 tween A clique is a complete graph, in which there is an edge between every pair of the vertic
HDU - 5952 Counting Cliques(DFS)
A clique is a complete graph, in which there is an edge between every pair of the vertices. Given a graph with N vertices and M edges, your task is to co
HDU 3450 Counting Sequences(樹狀陣列+離散化+二分+dp思想 詳細解答)
題意:給出一段序列,讓你找出一段子序列(長度>=2)滿足序列中每相鄰的兩個數之間的差 <=d,求出這樣的序列的個數。 思路:本題利用dp思想,dp[i] 表示 以 i 為結尾的子序列個數(主要是記錄) 以1 3 7 5 為例: 1
Counting Divisors((l~r)^k的因子數和)
題意:令d(x)表示x的因子數,求∑ri=ld(ik)∑i=lrd(ik),r,l 為1e12 ,r-l為1e6 解析: 剛開始想到的是尤拉函式值,結果ikik就勸退了,換一種常規的思路,從因子的角度去思考,按照基本定理:n=pq11∗pq22∗...p
HDU 2952 Counting Sheep
題目連結:傳送門 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the ceiling, for hours and hours. Then
HDU-6184 Counting Stars(暴力找三元環)
Counting Stars Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T
HDU 5952 Counting Cliques(暴搜)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
HDU 1264 Counting Squares (暴力水)
#include<bits/stdc++.h> using namespace std; #define debug puts("YES"); #define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++) #defi
hdu-5952 Counting Cliques(dfs&&優化)
完全圖概念 題意: 給一個無向圖,N(0-100)個頂點,M(0-1000)條邊,求圖中頂點數為S(1-10)的完全圖(任意兩個頂點都有一條邊相連)的個數。 思路: 最開始還以為是環,這鍋sls得背啊哈哈哈哈。 題解都在註釋裡了。 #include <ios
SPOJ DIVCNT2 - Counting Divisors (square)
題目描述: 求 ∑ i