您的位置:首页 > 其它

Hdu6069 Counting Divisors(2017多校第4场)

2017-08-03 23:00 253 查看


Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1105    Accepted Submission(s): 393


Problem Description

In mathematics, the function d(n) denotes
the number of divisors of positive integer n.

For example, d(12)=6 because 1,2,3,4,6,12 are
all 12's
divisors.

In this problem, given l,r and k,
your task is to calculate the following thing :

(∑i=lrd(ik))mod998244353

 

Input

The first line of the input contains an integer T(1≤T≤15),
denoting the number of test cases.

In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107).

 

Output

For each test case, print a single line containing an integer, denoting the answer.

 

Sample Input

3
1 5 1
1 10 2
1 100 3

 

Sample Output

10
48
2302

 

Source

2017 Multi-University Training Contest - Team 4

 

Recommend

liuyiding

—————————————————————————————————

题目的意思是求一个区间的每个数的因子数之和

思路:先去打一个1到1e6的素数表,然后去枚举每个素数在区间内的倍数,可以跳着枚举,计算出每个数对应的因子个数,对于每个数的因子个数就等于枚举的因子个数*k+1累乘起来,注意剩下的大素数的判断

比赛是也是素数打表枚举的 ,鬼知道怎么想的去枚举区间的每个数去求因子,妥妥TLE,也有过正解的想法,想过没想太透彻,感觉这种题值得好好反思警戒自己

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <functional>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;
const LL mod = 998244353;

bool vis[1000009];
LL prime[1000009], sum[1000009], a[1000009];
LL l, r, k;
int cnt;

void init()
{
memset(vis, true, sizeof vis);
vis[0] = vis[1] = false;
cnt = 0;
for (int i = 2; i < 1000009; i++)
{
if (!vis[i]) continue;
prime[cnt++] = i;
for (int j = i * 2; j < 1000009; j += i) vis[j] = false;
}
}

int main()
{
init();
int t;
scanf("%d", &t);
while (t--)
{
scanf("%lld%lld%lld", &l, &r, &k);
for (int i = 0; i <= r - l; i++) sum[i] = 1, a[i] = i + l;
LL ans = 0;
for (int i = 0; i < cnt; i++)
{
LL p = (l / prime[i] + (l%prime[i] ? 1 : 0))*prime[i];
for (LL j = p; j <= r; j += prime[i])
{
int res = 0;
while (a[j - l] % prime[i] == 0) res++, a[j - l] /= prime[i];
sum[j - l] = sum[j - l] * ((1LL * res*k + 1) % mod) % mod;
}
}
for (int i = 0; i <= r - l; i++)
{
if (a[i] != 1) sum[i] = sum[i] * (k + 1) % mod;
ans = (ans + sum[i]) % mod;
}
printf("%lld\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: