并不对劲的bzoj2820:p2257:YY的GCD
题目大意
\(t\)(\(t\leq10^4\))组数据,给定\(n,m\)(\(n,m\leq10^6\))求
\]
题解
这个人(点这里)讲得很清楚\(\color{white}{\text{shing太强了}}\)
代码
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define rep(i,x,y) for(register int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)
#define maxn 10000010
#define lim (maxn-10)
#define LL long long
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
void write(LL x)
{
if(x==0){putchar('0'),putchar('\n');return;}
int f=0;char ch[20];
if(x<0)putchar('-'),x=-x;
while(x)ch[++f]=x%10+'0',x/=10;
while(f)putchar(ch[f--]);
putchar('\n');
return;
}
int t,n,m,p[maxn],no[maxn],mu[maxn],cnt;
LL f[maxn];
int main()
{
no[1]=mu[1]=1;
rep(i,2,lim)
{
if(!no[i])p[++cnt]=i,mu[i]=-1;
for(int j=1;j<=cnt&&i*p[j]<=lim;j++)
{
no[i*p[j]]=1;
if(i%p[j]==0){mu[i*p[j]]=0;break;}
mu[i*p[j]]=-mu[i];
}
}
rep(i,1,cnt)for(int j=p[i];j<=lim;j+=p[i])f[j]+=mu[j/p[i]];
rep(i,1,lim)f[i]+=f[i-1];
t=read();
while(t--)
{
n=read(),m=read();
if(n>m)swap(n,m);LL ans=0;
for(int l=1,r=0;l<=n;l=r+1)r=min(n/(n/l),m/(m/l)),ans+=(LL)(n/l)*(LL)(m/l)*(f[r]-f[l-1]);
write(ans);
}
return 0;
}
并不对劲的bzoj2820:p2257:YY的GCD的更多相关文章
- 【BZOJ2820】YY的GCD(莫比乌斯反演)
[BZOJ2820]YY的GCD(莫比乌斯反演) 题面 讨厌权限题!!!提供洛谷题面 题解 单次询问\(O(n)\)是做过的一模一样的题目 但是现在很显然不行了, 于是继续推 \[ans=\sum_{ ...
- 【BZOJ2820】YY的GCD
[BZOJ2820]YY的GCD Description 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的( ...
- 洛谷 P2257 YY的GCD
洛谷 P2257 YY的GCD \(solution:\) 这道题完全跟[POI2007]ZAP-Queries (莫比乌斯反演+整除分块) 用的一个套路. 我们可以列出答案就是要我们求: \(ans ...
- P2257 YY的GCD
P2257 YY的GCD 题目描述 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 k ...
- [Luogu P2257] YY的GCD (莫比乌斯函数)
题面 传送门:洛咕 Solution 推到自闭,我好菜啊 显然,这题让我们求: \(\large \sum_{i=1}^{n}\sum_{j=1}^{m}[gcd(i,j)\in prime]\) 根 ...
- 题解 P2257 YY的GCD
P2257 YY的GCD 解题思路 果然数论的题是真心不好搞. 第一个莫比乌斯反演的题,好好推一下式子吧..(借鉴了blog) 我们要求的答案就是\(Ans=\sum\limits_{i=1}^{n} ...
- 【反演复习计划】【bzoj2820】YY的GCD
这题跟2818一样的,只不过数据水一点,可以用多一个log的办法水过去…… 原题意思是求以下式子:$Ans=\sum\limits_{isprime(p)}\sum\limits_{i=1}^{a}\ ...
- 【BZOJ2820】YY的GCD [莫比乌斯反演]
YY的GCD Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 求1<=x<=N, ...
- BZOJ2820:YY的GCD——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2820 Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x& ...
随机推荐
- 性能测试工具 - ab 简单应用
之前知道一般网站性能可以通过 LoadRunner, JMeter, QTP 等相应的软件进行测试, 印象中本科学习 “软件测试” 这门课程时安装并使用过, LoadRunner等不是一个小软件, 安 ...
- [luoguP2577] [ZJOI2005]午餐(DP)
传送门 显然吃饭时间越长的人排在前面越好,所以先排序. f[i][j]表示前i个人,A队的打饭时间为j的最优解,每个人只有两种选择,去A队或是去B队. #include <cstdio> ...
- git push ‘No refs in common and none specified’doing nothing问题解决
git push ‘No refs in common and none specified’doing nothing问题解决 输入git push origin master即可解决问题
- Gym 215177D 母亲节的礼物
Gym 215177D 母亲节的礼物 Problem : 给n个点m条边的无向图,每个点的度数小于等于7,要求用4种不同的颜色给每个点染色,使得每个点相邻的点中最多只有一个相同颜色的点.(n<= ...
- 理解流方式上传和form表单上传
流方式上传: $post_input = 'php://input'; $save_path = dirname( __FILE__ ); $postdata = file_get_contents( ...
- equals() 和 hashCode()
equals() 和 hashCode()这两个方法在java.lang.Object中,所有的类都可以继承这两个方法: 但是,这两个方法在Object类中的实现一般没什么用,所以你通常需要自己重载这 ...
- HDU 6396 贪心+优先队列+读入挂
Swordsman Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 洛谷——P2916 [USACO08NOV]为母牛欢呼Cheering up the Cows
https://www.luogu.org/problem/show?pid=2916 题目描述 Farmer John has grown so lazy that he no longer wan ...
- Meteor教程
Meteor 是一个构建在 Node.js 之上的平台,用来开发实时网页程序.Meteor 程序位于数据库和用户界面之间,保持二者之间的数据同步更新. 因为 Meteor 是基于 Node.js 开发 ...
- 【stl学习笔记】vector
vector是定义于namespace std内的template: namespace std { template<class T, class Allocator = allocator& ...