其实这个用的是Mobius反演的第二种形式

F(d) = (n div d) * (m div d)

f(d) = [ gcd(i,j)=d ] (i in [1,a], j in [1,b])

 /**************************************************************
Problem: 1101
User: idy002
Language: C++
Result: Accepted
Time:6764 ms
Memory:1688 kb
****************************************************************/ #include <cstdio>
#include <iostream>
using namespace std; typedef long long dnt; int prm[], isnot[], mu[], ptot; void init( int n ) {
mu[] = ;
for( int i=; i<=n; i++ ) {
if( !isnot[i] ) {
prm[++ptot] = i;
mu[i] = -;
}
for( int j=; j<=ptot && i*prm[j]<=n; j++ ) {
isnot[i*prm[j]] = true;
if( i%prm[j]== ) {
mu[i*prm[j]] = ;
break;
}
mu[i*prm[j]] = -mu[i];
}
}
for( int i=; i<=n; i++ )
mu[i] += mu[i-];
}
dnt calc( int n, int m, int k ) {
dnt rt = ;
if( n>m ) swap(n,m);
n/=k;
m/=k;
for( int d=; d<=n; d++ ) {
int dd=min(n/(n/d),m/(m/d));
rt += (dnt)(n/d)*(m/d)*(mu[dd]-mu[d-]);
d=dd;
}
return rt;
}
int main() {
init();
int T;
scanf( "%d", &T );
while( T-- ) {
int n, m, k;
scanf( "%d%d%d", &n, &m, &k );
printf( "%lld\n", calc(n,m,k) );
}
}

bzoj 1101的更多相关文章

  1. BZOJ 1101 Luogu P3455 POI 2007 Zap (莫比乌斯反演+数论分块)

    手动博客搬家: 本文发表于20171216 13:34:20, 原地址https://blog.csdn.net/suncongbo/article/details/78819470 URL: (Lu ...

  2. BZOJ 1101: [POI2007]Zap

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2262  Solved: 895[Submit][Status] ...

  3. BZOJ 1101 Zap(莫比乌斯反演)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 给定a,b,d,求有多少gcd(x,y)==d(1<=x<=a&& ...

  4. BZOJ 1101 [POI2007]Zap(莫比乌斯反演)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1101 [题目大意] 求[1,n][1,m]内gcd=k的情况 [题解] 考虑求[1,n ...

  5. BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )

    求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...

  6. bzoj 1101 [POI2007]Zap——反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 #include<cstdio> #include<cstring& ...

  7. BZOJ 1101 [POI2007]Zap | 第一道莫比乌斯反(繁)演(衍)

    题目: http://www.lydsy.com/JudgeOnline/problem.php?id=1101 题解: http://www.cnblogs.com/mrha/p/8203612.h ...

  8. bzoj 1101 zap 莫比乌斯

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给 ...

  9. bzoj 1101 Zap —— 莫比乌斯反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...

随机推荐

  1. 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)

    题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...

  2. NYOJ 133 子序列 (离散化)

    题目链接 描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 8 8 1 1,所求子串就是2 8 8 8 1. 输入 第一行输入一个整 ...

  3. let块级作用域

    let是es6中新加的作用域,即块级作用域. var申明的变量要么全局,要么函数级,而let允许把变量的作用域限制在块级域中,这里的块级可以是()内,或{}内. 示例: code_1: "u ...

  4. JS 判断手机操作系统代码

    还是利用UA, 返回值: ios, android, unknown function getMobileType () { var ua = window.navigator.userAgent.t ...

  5. C++学习之路(十):虚继承引入的执行效率

    这篇文章不知道取啥名字了,暂且这样叫,直接看场景就明白了.节选自<深度探索C++对象模型> Point3d origin, *pt = &origin; (1)origin.x = ...

  6. ltib安装过程中遇到好多问题,从网上转来的好多份总结

    最近调试MPC5125的板子,第一步LTIB都装不过去,挫败感十足. LTIB的安装镜像来自于freescale的ltib-mpc5121ads-200906,是用于Ubuntu 10版本之前的,现在 ...

  7. PHP 不让标准浏览器(firfox,chrome等)走浏览器的缓存页面

    或在HTML页面里加: <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache,no-store, must-reva ...

  8. 「pycaffe指南」使用caffe的NetSpec.py中的Python接口自动生成×.prototxt文件

    https://www.jianshu.com/p/1a420445deea 作者:MapReducer 链接:https://www.jianshu.com/p/1a420445deea 來源:简书 ...

  9. Python模块之pxssh

    pxssh模块用于在python中ssh远程连接,执行命令,返回结果,但注意不支持Windows系统 #!/usr/bin/env python #-*- coding:utf-8 -*- from ...

  10. POJ 2513 Colored Sticks(Tire+欧拉回(通)路判断)

    题目链接:http://poj.org/problem?id=2513 题目大意:你有好多根棍子,这些棍子的两端分都别涂了一种颜色.请问你手中的这些棍子能否互相拼接,从而形成一条直线呢? 两根棍子只有 ...