【HDOJ】1695 GCD
莫比乌斯反演简单题目。
/* 1695 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = ;
int P[maxn];
bool visit[maxn];
int mu[maxn], m = ; void init() {
int i, j, k; memset(visit, false, sizeof(visit));
mu[] = ;
for (i=; i<maxn; ++i) {
if (!visit[i]) {
P[m++] = i;
mu[i] = -;
}
for (j=; j<m; ++j) {
k = P[j] * i;
if (k > maxn)
break;
visit[k] = true;
if (i%P[j] == ) {
mu[k] = ;
break;
} else {
mu[k] = -mu[i];
}
}
}
} int main() { #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int a, b, c, d, k;
int tt;
__int64 ans, tmp; init();
scanf("%d", &tt);
rep(t, , tt+) {
scanf("%d %d %d %d %d",&a,&b,&c,&d,&k);
if (k == ) {
ans = ;
} else {
b /= k;
d /= k;
if (b > d)
swap(b, d);
ans = tmp = ;
rep(i, , b+)
ans += 1LL * mu[i] * (b/i) * (d/i);
rep(i, , b+)
tmp += 1LL * mu[i] * (b/i) * (b/i);
#ifndef ONLINE_JUDGE
printf("%I64d %I64d\n", ans, tmp);
#endif
ans -= tmp/;
}
printf("Case %d: %I64d\n", t, ans);
} #ifndef ONLINE_JUDGE
printf("time = %d\n", (int)(clock()));
#endif return ;
}
【HDOJ】1695 GCD的更多相关文章
- 【HDOJ】3071 Gcd & Lcm game
刚开始看这个题目,觉得没法做.关键点是数据小于100.因此,可以枚举所有小于100的素因子进行位压缩.gcd就是求最小值,lcm就是求最大值.c++有时候超时,g++800ms.线段树可解. /* 3 ...
- 【精】iOS GCD 具体解释
一.介绍 1.什么是GCD? Grand Central Dispatch.是苹果公司开发的一套多核编程的底层API. GCD首次公布在Mac OS X 10.6,iOS4及以上也可用.GCD存在于l ...
- 【HDOJ】4983 Goffi and GCD
题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【数论】二进制GCD
二进制GCD GCD这种通用的算法相信每个OLER都会 ,辗转相除,代码只有四行 : int GCD(int a,int b){ if(b==0) return a; return GCD(b ...
- 【BZOJ】2818: Gcd(欧拉函数/莫比乌斯)
http://www.lydsy.com/JudgeOnline/problem.php?id=2818 我很sb的丢了原来做的一题上去.. 其实这题可以更简单.. 设 $$f[i]=1+2 \tim ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
随机推荐
- javaweb常用工具类及配置文件备份
Javaweb常用工具类及配置文件备份 做一个代码备份,以后常用到的. hibernate工具类备份 package com.dly.service; /* * hibernate获取sessi ...
- jsp 页面获取xml的内容
<c:out value="${history.xml}" escapeXml="true" />
- ios 调用js方法(ios监听js方法执行)
下载地址 https://pan.baidu.com/s/1cJvEsY
- js使用正则表达式去空格
写成类的方法格式如下:(str.trim();) <script language="javascript"> String.prototype.trim=functi ...
- javax.el.PropertyNotFoundException: Property 'aDesc' not found on type
这个问题是是在我使用jeesite自动代码是产生的,原因是实体类的属性命名规范不合格,我在网上看到类的属性前三个字母不能出现大写 解决办法:将类的属性大小写改一下
- (hdu)5546 Ancient Go
Problem Description Yu Zhou likes to play Go with Su Lu. From the historical research, we found that ...
- 通过 OpenNI 建立 Kinect 3D Point Cloud
這篇還是算延續前一篇的<透過 OpneNI 合併 Kinect 深度以及彩色影像資料>.在可以透過 OpenNI 讀取到 Kinect 的深度.色彩資訊之後,其實就可以試著用這些資訊,來重 ...
- c++ primer复习(四)
1 标准库容器 顺序容器:vector.list.deque 容器适配器:stack.queue.priority_queue 2 容器元素类型约束: 容器元素类型必须支持复制和赋值,因为容器存放的都 ...
- (转)Libevent(5)— 连接监听器
转自:http://name5566.com/4220.html 参考文献列表:http://www.wangafu.net/~nickm/libevent-book/ 此文编写的时候,使用到的 Li ...
- Kali linux网络配置
Kali linux 安装完成后,需要对其网络进行配置.使用DHCP服务是配置网卡最简单的方法之一,但渗透测试时通常不会这样做,因为系统会被记录在DHCP服务器的数据库中. 1 动态DHCP方式 配 ...