HDU 6069 题解
来源:互联网 发布:淘宝助理数据包 编辑:程序博客网 时间:2024/06/13 21:38
转载请注明出处:http://blog.csdn.net/Bule_Zst/article/details/76794810
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6069
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 :
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≤
Output
For each test case, print a single line containing an integer, denoting the answer.
Sample Input
31 5 11 10 21 100 3
Sample Output
10482302
题意:
d(x)表示x的因子的个数,求公式的值
方法:
首先枚举出小于
接着,根据公式计算结果
公式:若
代码:
#include<cstdio>typedef long long ll;const int N=1000010,P=998244353;int Case,i,j,k,p[N/10],tot,g[N],ans;ll n,l,r,f[N];bool v[N];void work( ll p ){ // 传入一个素数,对f数组进行检验,如果该素数是其因子,则循环除尽,并更新g数组相应元素 for( ll i = l / p * p; i <= r; i += p ) if(i>=l) { int o=0; while( f[i-l] % p == 0 ) f[i-l]/=p,o++; g[i-l] = 1LL * g[i-l] * ( o * k + 1 ) % P; }}int main(){ // 将小于N的素数存在p数组中 for(i=2;i<N;i++){ if(!v[i])p[tot++]=i; for(j=0;j<tot&&i*p[j]<N;j++){ v[i*p[j]]=1; if(i%p[j]==0)break; } } scanf("%d",&Case); while(Case--){ scanf("%lld%lld%d",&l,&r,&k); n=r-l; // f数组存储输入的数,g数组存储对应的答案 for(i=0;i<=n;i++) f[i]=i+l,g[i]=1; // 只需循环到根号r,因为大于等于根号r的数是不可能成为小于r的数的因子的 for(i=0;i<tot;i++){ if(1LL*p[i]*p[i]>r) break; work(p[i]); } // 计算结果 for( ans = i = 0; i <= n; i++ ) { if(f[i]>1) // 如果f[i]大于1,则意味着,之前的所有素数都不是它的因子,那么它自身一定是素数 g[i]=1LL*g[i]*(k+1)%P; ans=(ans+g[i])%P; } printf("%d\n",ans); } return 0;}
- HDU 6069 题解
- hdu 4602题解
- hdu 1789题解
- HDU 4665 题解
- HDU 4710题解
- HDU 4715题解
- hdu 1087题解
- hdu 2844题解
- hdu 2845 题解
- hdu 4007题解
- hdu 4004题解
- hdu 1879题解报告
- HDU 2180 时钟 题解
- HDU 1425 sort 题解
- HDU 1015 Safecracker 题解
- HDU Computer Transformation1041 题解
- HDU 题解 1024
- hdu 4451Dressing题解
- 关于tensorflow 用于线性回归及MNIST 数字识别中的一些思考及补充
- CyclicBarrier同时执行
- Java密码学
- java面试题,各大企业常见的java笔试题之二
- 马尔可夫链算法原理与实现
- HDU 6069 题解
- 2017年8月6日21:42:57
- Error running app.main: This version of Android Studio is incompatible with the Gradle Plugin used.
- HorizontalScrollView+TabLayout+ViewPager+XUtils
- 为什么说 DOM 操作很慢
- shell脚本实现希尔排序
- android databinding BindingAdapter [xml imageUrl加载图片]
- ubuntu14.04下anaconda安装openai_gym
- storm目录结构及在zk中的目录结构