莫比乌斯反演简单题目。

 /* 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. asp.net:用类来后台绑定数据源

    //封装成一个 using System;using System.Collections.Generic;using System.Linq;using System.Web;using Syste ...

  2. call与apply的区别

    /** * 用 add 来替换 sub,add.call(sub,3,1) == add(3,1) ,所以运行结果为:alert(4); */ function add(a,b){ alert(a+b ...

  3. JS数值输入控制

    在html文本框录入数值时,可用如下方法进行控制判断. 整数:<input type="text" name="aaa" onkeypress=" ...

  4. java之内存管理

    对于JVM的垃圾回收机制来说,是否回收一个对象的标准在于:是否还有引用变量引用该对象,只要有引用变量引用该对象,垃圾回收机制就不会回收它. 强引用:创建一个对象,并把这个对象赋给一个引用变量.这种引用 ...

  5. UVA 11078 Open Credit System(扫描 维护最大值)

    Open Credit System In an open credit system, the students can choose any course they like, but there ...

  6. 九度OJ 1107 搬水果 -- 哈夫曼树 2011年吉林大学计算机研究生机试真题

    题目地址:http://ac.jobdu.com/problem.php?pid=1107 题目描述: 在一个果园里,小明已经将所有的水果打了下来,并按水果的不同种类分成了若干堆,小明决定把所有的水果 ...

  7. zabbix 配置

    终于把zabbix配置好了.可能还有待优化   我主要参考了几个链接 http://lnmp.org/install.html   一键安装lnmp http://blog.unix178.com/2 ...

  8. Trac与Apache的配合

    将Trac与Apache配合使用,需要用到mod_wsgi模块,首先Apache要安装负责wsgi的模块. def application(environ, start_request): #... ...

  9. c#基础班笔记

    1.静态与非静态的区别:是否有static 非静态: 1)在非静态类中,既可以有实例成员,也可以有静态成员 2)在调用实例成员,通过  对象.实例成员 在调用静态成员时,通过  类名.静态成员 静态: ...

  10. 隐性改变display类型

    有一个有趣的现象就是当为元素(不论之前是什么类型元素,display:none 除外)设置以下 2 个句之一: position : absolutefloat : left 或 float:righ ...