码迷,mamicode.com
首页 > 其他好文 > 详细

hdu6069[素数筛法] 2017多校3

时间:2017-08-03 23:43:08      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:sts   isp   can   turn   lld   i++   nbsp   its   ==   

/*hdu6069[素数筛法] 2017多校3*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL l, r, k;
const LL MOD = 998244353LL;
int T, n, prime[1100000], primesize;
bool isprime[11000000];
void getlist(int listsize)
{
    memset(isprime, 1, sizeof(isprime));
    isprime[1] = false;
    for (int i = 2; i <= listsize; i++)
    {
        if (isprime[i])prime[++primesize] = i;
        for (int j = 1; j <= primesize && i * prime[j] <= listsize; j++)
        {
            isprime[i * prime[j]] = false;
            if (i % prime[j] == 0)break;
        }
    }
}
LL num[1000005], ans[1000005];
void solve() {
    LL n = r - l + 1;
    for (int i = 0; i < n; i++) {
        num[i] = i + l;
        ans[i] = 1;
    }
    for (int i = 1; (LL)prime[i]*prime[i] <= r; i++) {
        for (LL j = prime[i] * (l / prime[i]); j <= r; j += prime[i]) {
            if (j < l) continue;
            LL cnt = 0;
            while (num[j - l] % prime[i] == 0) {
                cnt++;
                num[j - l] /= prime[i];
            }
            ans[j - l] = (ans[j - l] * (1LL + cnt * k)) % MOD;
        }
    }
    LL res = 0;
    for (int i = 0; i < n; i++) {
        if (num[i] > 1) {
            ans[i] = (ans[i] * (1LL + k)) % MOD;
        }
        res = (res + ans[i]) % MOD;
    }
    printf("%lld\n", res);
}
int main() {
    getlist(1000005);
    scanf("%d", &T);
    while (T--) {
        scanf("%lld%lld%lld", &l, &r, &k);
        solve();
    }
    return 0;
}

 

hdu6069[素数筛法] 2017多校3

标签:sts   isp   can   turn   lld   i++   nbsp   its   ==   

原文地址:http://www.cnblogs.com/UnderSilenceee/p/7282594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!