DZY Loves Math [Bzoj 3309]
来源:互联网 发布:腾讯网络加速小助手 编辑:程序博客网 时间:2024/05/20 23:55
题目地址请点击——
DZY Loves Math
Description
对于正整数
例如
给定正整数
Input
第一行一个数
接下来
Output
对于每一个询问,输出一行一个非负整数作为回答。
Sample Input
4
7558588 9653114
6514903 4451211
7425644 1189442
6335198 4957
Sample Output
35793453939901
14225956593420
4332838845846
15400094813
Hint
Solution
令
设
令
要使
设
所以
(1)
当且仅当
否则,
(2)
当且仅当
否则,
综上,当
求出
Code
#include <iostream>#include <cstdio>#define LL long long#define MAXN 10000000#define Min(x,y) ((x)<(y)?(x):(y))using namespace std;LL T,n,m;bool no_prime[MAXN+10];LL prime[MAXN+10];LL sum[MAXN+10];LL g[MAXN+10];LL ci[MAXN+10];LL rci[MAXN+10];int main(){ sum[1]=0; for(LL i=2;i<=MAXN;i++){ if(!no_prime[i]){prime[++prime[0]]=i;ci[i]=i;g[i]=1;rci[i]=1;} for(LL j=1;prime[j]*i<=MAXN;j++){ no_prime[prime[j]*i]=true; if(i%prime[j]==0){ rci[prime[j]*i]=rci[i]+1; ci[prime[j]*i]=ci[i]*prime[j]; if(prime[j]*i/ci[prime[j]*i]==1)g[prime[j]*i]=1; else if(rci[prime[j]*i]==rci[prime[j]*i/ci[prime[j]*i]])g[prime[j]*i]=g[prime[j]*i/ci[prime[j]*i]]*(-1); break; } rci[prime[j]*i]=1; ci[prime[j]*i]=prime[j]; if(prime[j]*i/ci[prime[j]*i]==1)g[prime[j]*i]=1; else if(rci[prime[j]*i]==rci[prime[j]*i/ci[prime[j]*i]])g[prime[j]*i]=g[prime[j]*i/ci[prime[j]*i]]*(-1); } sum[i]=sum[i-1]+g[i]; } scanf("%lld",&T); while(T--){ LL ans=0; scanf("%lld%lld",&n,&m); if(n==0||m==0){ printf("0\n"); continue; } if(n>m)swap(n,m); for(LL i=1,it;i<=n;i=it+1){ it=Min(n/(n/i),m/(m/i)); ans+=(sum[it]-sum[i-1])*(n/i)*(m/i); } printf("%lld\n",ans); } return 0;}
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- BZOJ 3309: DZY Loves Math
- bzoj 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math
- 【线性筛】【bzoj 3309】: DZY Loves Math
- bzoj 3309: DZY Loves Math (反演)
- 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math 莫比乌斯反演
- bzoj 3309: DZY Loves Math 莫比乌斯反演
- BZOJ 3560 DZY Loves Math V 数论
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- BZOJ 3512: DZY Loves Math IV
- [杜教筛] BZOJ 3512 DZY Loves Math IV
- 【BZOJ 3560】【数论】DZY Loves Math V
- 【bzoj 3512】DZY loves math IV
- bzoj 3560 DZY Loves Math V
- 【只需3步】源码手动安装Apache以及配置(亲测可行)
- 【只需3步】Linux php的安装与配置[源码安装]
- Spring 中配置sessionFactory及用法
- thrift 基础知识点整理 server protocol transport
- win7下Qt5使用mysql C++编程配置
- DZY Loves Math [Bzoj 3309]
- 基于Qt5.5.0的sql,C++备忘录软件的编写
- Qt使用自带的windeployqt 生成exe来发布软件
- Qt model和tableview的使用
- Android中使用抖动动画吸引来用户注意
- 基于Qt5.5.0的sql数据库、SDK_tts文本语音朗读的CET四六级单词背诵系统软件的编写V1.0
- VC6.0 C++ 如何调用微软windows系统SDK 语音API
- 给超链接添加onclick事件
- JQuery EasyUI 引用加载分析、文件分析