莫比乌斯反演简单题目。

 /* 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的更多相关文章

  1. 【HDOJ】3071 Gcd & Lcm game

    刚开始看这个题目,觉得没法做.关键点是数据小于100.因此,可以枚举所有小于100的素因子进行位压缩.gcd就是求最小值,lcm就是求最大值.c++有时候超时,g++800ms.线段树可解. /* 3 ...

  2. 【精】iOS GCD 具体解释

    一.介绍 1.什么是GCD? Grand Central Dispatch.是苹果公司开发的一套多核编程的底层API. GCD首次公布在Mac OS X 10.6,iOS4及以上也可用.GCD存在于l ...

  3. 【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不为 ...

  4. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  5. 【数论】二进制GCD

    二进制GCD     GCD这种通用的算法相信每个OLER都会 ,辗转相除,代码只有四行 : int GCD(int a,int b){ if(b==0) return a; return GCD(b ...

  6. 【BZOJ】2818: Gcd(欧拉函数/莫比乌斯)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2818 我很sb的丢了原来做的一题上去.. 其实这题可以更简单.. 设 $$f[i]=1+2 \tim ...

  7. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  8. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  9. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

随机推荐

  1. VS2013+SVN管理

    进入新公司,大部分员工使用的是VS2013 ,所以搜集了下支持VS2013的一些SVN工具,现在发布到园子,供大家使用. CodeMaid插件,能够很好的格式化代码,强迫症的最爱: TortoiseS ...

  2. C#做的一个加密/解密的类

    转自:http://www.16aspx.com/Article/3904 using System; using System.Security.Cryptography; using System ...

  3. SQL SERVER格式化字符串位数,不足补零

    本文举例在SQLSERVER中将1格式化为001的方法: 1.方法一SQL语句执行如下: ,) as col 2.方法二SQL语句执行如下: ,) ,) as col 下面是C#代码实现方法: ; & ...

  4. 那天有个小孩跟我说LINQ(二)转载

    1  LINQ TO Objects续(代码下载)      新建项目 linq_Ch2控制台程序,新建一个Entity文件夹    1.1 学生成绩查询(练习Join)         有三张表如下 ...

  5. Oracle在表上建立自增字段的方法

    本方法为使用SEQUENCE(序列)   例如有表temp_test结构为: create table TEMP_TEST ( id number, nm varchar(10), primary k ...

  6. YYKit之YYText

    原文:http://www.cnblogs.com/lujianwenance/p/5716804.html   本文的目的是希望能帮助到我们更快的熟悉和学习YYText的结构和实现的思路,如有不正确 ...

  7. UIAlertController基本使用

      从ios8之后,系统的弹框 UIAlertView 与 UIActionSheet 两个并在一了起, 使用了一个新的控制器叫 UIAlertController UIAlertController ...

  8. iOS中RGB颜色转换

    iOS中RGB常用的色值,同时可将对颜色的设置定义成宏,方便开发应用,如: // RGB颜色转换(16进制->10进制) #define UIColorFromRGB(rgbValue) [UI ...

  9. HDU 2809 God of War(DP + 状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 题目大意:给出战神吕布的初始攻击力ATI.防御力DEF.生命值HP.每升一级增加的攻击力In_A ...

  10. Speak softly love

    Speak softly love and hold me warm against your heart 柔声诉情,拥我在你暖暖的心上 I feel your words, the tender t ...