HDU
来源:互联网 发布:外贸通软件 编辑:程序博客网 时间:2024/05/21 22:37
莫比乌斯反演裸题,描述很明确,就不翻译了。
Description
There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) point. He wonders how many trees he can see.
If two trees and Sherlock are in one line, Farmer Sherlock can only see the tree nearest to him.
Input
The first line contains one integer t, represents the number of test cases. Then there are multiple test cases. For each test case there is one line containing two integers m and n(1 ≤ m, n ≤ 100000)
Output
For each test case output one line represents the number of trees Farmer Sherlock can see.
Sample Input
2
1 1
2 3
Sample Output
1
5
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define mem(s,t) memset(s,t,sizeof(s))#define D(v) cout<<#v<<" "<<v<<endl#define inf 0x3f3f3f3fconst int maxn =100000+5;ll tot=0,n,m;int miu[maxn],prime[maxn];bool isPrime[maxn];void getmiu(){ mem(isPrime,true); miu[1]=1; for(int i=2;i<=maxn;i++){ if(isPrime[i]) prime[tot++]=i,miu[i]=-1; for(int j=0;j<=tot;j++){ if(i*prime[j]>=maxn) break; isPrime[i*prime[j]]=false; if(i%prime[j]==0){ miu[i*prime[j]]=0; break; }else miu[i*prime[j]]=-1*miu[i]; } }}void solve(){ int T;scanf("%d",&T); while(T--){ ll ans=0; scanf("%d%d",&m,&n); int minn=min(m,n); for(ll i=1;i<=minn;i++){ ans+=(ll)(m/i)*(n/i)*miu[i]; } printf("%lld\n",ans); }}int main(){#ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);#endif getmiu(); solve(); return 0;}
1 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- Java并发编程实战
- 基于QT的学生信息管理系统开发
- mysql安装
- 加密与解密入门
- [深度学习论文笔记][CVPR 16]Deep Metric Learning via Lifted Structured Feature Embedding
- HDU
- 稀疏矩阵的压缩存储与转置与加法
- linux安装jupyter
- hdu 1024和hdu 1244 两个最大和子序列 dp 优化
- AC自动机(hdu2222)
- Prufer数列编码生成树
- linux vi模式下基本命令和快捷键
- vb.net 教程 5-8 Screen类
- 迷宫问题 POJ