HDU 6069 Count Divisor 数学+思维
来源:互联网 发布:世爵娱乐软件 编辑:程序博客网 时间:2024/06/06 01:46
In mathematics, the function d(n) d(n) denotes the number of divisors of positive integern n.
For example,d(12)=6 d(12)=6 because 1,2,3,4,6,12 1,2,3,4,6,12 are all 12 12's divisors.
In this problem, givenl,r l,r and k k, your task is to calculate the following thing :
(∑i=lrd(ik))mod998244353 (∑i=lrd(ik))mod998244353
For example,
In this problem, given
In each test case, there are
31 5 11 10 21 100 3
10482302
本题刚开始看到感觉有点蒙
后来发现 其实d(x^k) = d((p1^k1*p2^k2*p2^k2*p3^k3...pn^kn)^k) = d(p1^(k1*k)*p2^(k2*k)*p2^(k2*k)*...pn^(kn*k))= (k1*k+1)*(k2*k+1)*(k3*k+1)*(k4*k+1)*...(kn*k+1)
再从l到r对d(i)求和
一开始的想法打算枚举l到r然后每个元素对质数进行试除 得到因子的指数 果断超时
后来又用了二分还是超时
原来这道题由于范围是l,r的最大范围是1e12 所以可以筛出1e6的质因子
然后枚举其中的质因子 将其定位到l到r的区间内 对l到r区间内的数字除此因子
然后记录质数 最后l到r里面剩下的合数都是1 质数不变 此时在枚举区间去指数求和求的答案
还是很巧妙的一个解法 枚举因子 而不是枚举区间
#include<bits/stdc++.h>using namespace std;const int MAXN= 1e6+10;const int mod = 998244353;typedef long long ll;ll t,size;ll l,r,k;ll prime[MAXN],cnt[MAXN],q[MAXN];bool vis[MAXN];void init(){ for(int i=2;i<=1000000;i++) { if(!vis[i]){ prime[size++]=i; for(int j = i+i;j<=1000000;j+=i){ vis[j]=1; } } }}int main(){ init();// cout<<size<<endl; scanf("%d",&t); // freopen("out.txt","w",stdout); while(t--) { scanf("%lld%lld%lld",&l,&r,&k); ll ans = 0; if(l==1)ans++,l++; for(ll i=0;i<=r-l;i++)q[i] = l+i,cnt[i]=1; for(ll i=0;prime[i]*prime[i]<=r;i++){ ll lim = l/prime[i] + (l%prime[i]!=0); for(ll j=lim*prime[i];j<=r;j+=prime[i]){ ll tem = 0; while(q[j-l]%prime[i]==0)q[j-l]/= prime[i],tem++; cnt[j-l]=(cnt[j-l]*(tem*k+1)),cnt[j-l]%mod; } } for(ll i=0;i<=r-l;i++) { if(q[i]!=1)ans=(ans+cnt[i]*(k+1))%mod; else ans=(ans+cnt[i])%mod; } printf("%lld\n", ans%mod); } // fclose(stdout); return 0;}
阅读全文
0 0
- HDU 6069 Count Divisor 数学+思维
- hdu 5207 Greatest Greatest Common Divisor【筛法】【思维】
- hdu 4950 Monster (数学思维)
- HDU 5984 Pocky 【思维 数学】
- hdu 4472 Count【思维+dp】好题
- Hdu 6016 Count the Sheep【思维】
- hdu 6016 Count The Sheep 思维
- HDU:6016 Count the Sheep(思维)
- HDU 6016 Count the Sheep【思维】
- HDU-6016(思维)(Count the sheep)
- HDU 5056 Boring count(数学)
- HDU 4472 Count(数学 递归)
- HDU 4372 Count the Buildings 组合数学
- HDU 4588 Count The Carries(数学)
- hdu 4104 Discount (思维 数学归纳法)
- hdu 4710 Balls Rearrangement (数学思维)
- hdu 4091 数学思维题贪心
- 【HDU】-1214-圆桌会议(数学,思维)
- js 的删除方法和 filter的过滤删除方法对比
- 红黑树理解-插入删除
- 类中内容在内存中到底是如何分配的呢?
- 类模板
- 自定义控件(12)回传事件IPostBackEventHandler
- HDU 6069 Count Divisor 数学+思维
- [编程题] 序列交换
- Eigen: C++开源矩阵计算工具——Eigen的简单用法
- table-layout
- 事务的实现方案
- 搭建virtual private server
- 找出无序数组的最长连续子数组
- 关系型数据的分布式处理系统MyCAT(1)—概述和基本使用教程
- js 原型继承分析