Sports
题目链接 : http://acm.hpu.edu.cn/problem.php?id=1184
或者 http://acm.nyist.net/JudgeOnline/problem.php?pid=1319
题目意思 : 给定三个整数N,M,K,在1<=a<=N和1<=b<=M的约束下,存在多少个不同的整数对(a,b)使得a∗b可以被K整除? 数据范围:1<=T<=10000,1<=N,M<=109,1<=K<=50000。
思路: 我们可以对于题目中的 K 进行因子对分解,假设分解后数对为(ai,bi); 再排序;
假设这个数对是 (x,y) 那么x或者y乘以一个整数肯定能被K整除;所以 会有这样的整数数对 有 (n/ai)*(m/bi) 个;
假设我们枚举按照ai的升序,bi 降序,那么对应符合条件的列数一定会减少,对应符合条件的行数一定会增多;
所以我们用
arr[i] 代表第i个因子对且不包含之前统计过列的数量,那么在计算arr[i] 的时候就需要减去与之前计算重复的哪一些 ? 所以,如果 ai 是 aj 的倍数 (ai%aj=0),那么 得到(bj%bi=0) 第i个数对与第j个数对的,所以i所在的列,那么一定是j统计过的,所以需要减去j那部分列;
可能说的不太清楚,或者我理解不深,请看代码自己想一想或许就懂了。
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h> using namespace std;
typedef long long LL;
const int INF=2e9+1e8;
const int MOD=1e9+;
const int MAXSIZE=1e6+;
const double eps=0.0000000001;
void fre()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
}
#define memst(a,b) memset(a,b,sizeof(a))
#define fr(i,a,n) for(int i=a;i<n;i++) const int MAXN=5e4+;
int arr[MAXN],fac[MAXN],myindex;
void init(int k)
{
myindex=;
for(int i=;i<=sqrt(k);i++)
if(k%i==) fac[myindex++]=i,fac[myindex++]=k/i;
}
int main(int argc,char *argv[])
{
int ncase,k;
scanf("%d",&ncase);
while(ncase--)
{
LL n,m;
scanf("%lld%lld%d",&n,&m,&k);
init(k);
sort(fac,fac+myindex);
LL ans=;
for(int i=;i<myindex;i++)
{
int a=fac[i],b=k/fac[i];
arr[i]=m/b; // 列数
for(int j=;j<i;j++)
if(a%fac[j]==) arr[i]-=arr[j];
//排除一些列数 : 如果 行号成倍数;就说明重复了;所以有 容斥
ans+=n/a*(arr[i]);
}
printf("%lld\n",ans);
}
return ;
} /**************************************************/
/** Copyright Notice **/
/** writer: wurong **/
/** school: nyist **/
/** blog : http://blog.csdn.net/wr_technology **/
/**************************************************/
Sports的更多相关文章
- English trip V2 - 6 Sports Teacher:Taylor Key:phrasal verbs
In this lesson you will learn to talk about sports. 课上内容(Lesson) # How many different sports can you ...
- 「AtCoder Grand018B」Sports Festival(暴力)
题目链接B - Sports Festival 题意 n(1~300)个人m(1~300)个活动,\(A_{ij}\)表示i第j喜欢的活动,每个人选择在举办的活动里最喜欢的,因此可以通过选择一些活动来 ...
- 新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial
新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial 作者:韩梦飞沙 Auth ...
- 5. Sports 体育运动
5. Sports 体育运动 (1) Sport is not only physically challenging,but it can also be mentally challenging. ...
- OpenJ_POJ C16D Extracurricular Sports 打表找规律
Extracurricular Sports 题目连接: http://acm.hust.edu.cn/vjudge/contest/122701#problem/D Description As w ...
- TZOJ 4007 The Siruseri Sports Stadium(区间贪心)
描述 The bustling town of Siruseri has just one sports stadium. There are a number of schools, college ...
- 【OpenJ_POJ C16D】Extracurricular Sports(构造,找规律)
题目求n个互不相同的数,满足其和为其lcm.我们把lcm看成一个线段,分割成长度不同的n份.当然分法有很多,我们只需要构造一个好想好写的.先分成两个二分之一,取其中一个二分之一再分成1/3和2/3,接 ...
- [HackerCup Round1 3] Winning at Sports (动态规划)
题目链接:https://www.facebook.com/hackercup/problems.php?pid=688426044611322&round=344496159068801 题 ...
- ZOJ 3757 Alice and Bob and Cue Sports(模拟)
题目链接 题意 : 玩台球.Alice 和 Bob,一共可以进行m次,Alice 先打.有一个白球和n个标有不同标号的球,称目标球为当前在桌子上的除了白球以外的数值最小的球,默认白球的标号为0.如果白 ...
- zoj 3757 Alice and Bob and Cue Sports 模拟
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757 #include<cstdio> #incl ...
随机推荐
- xcode创建一个工程的多个taget,便于测试和发布多个版本
背景:很多时候,我们需要在一个工程中创立多个target,也就是说我们希望同一份代码可以创建两个应用,放到模拟器或者真机上,或者是,我们平时有N多人合作开发,当测试的时候,在A这里装了一遍测A写的那块 ...
- 邁向IT專家成功之路的三十則鐵律 鐵律二十二:IT人升遷之道-無為
升遷管道是許多人求職時相當重要的考量之一,畢竟人除了很愛錢之外更愛顯赫的頭銜,然而在企業中越顯赫的頭銜,其背後通常有更多的罵名,因為許多人的高官厚爵都是踩著一群人的頭頂爬上去的,隨時哪一天跌了下來,都 ...
- VS"后生成事件" 菜单的使用
网上有很多的文章都在介绍怎样创建一个自己定义的dll文件,以及怎样使用一个dll文件,在此不在赘述.本文主要介绍怎样使用VS2008的"生成后事件"的命令行,将一个dll文件直接复 ...
- SharpSSH
SharpSSH sharpssh is a pure .NET implementation of the SSH2 client protocol suite. It provides an AP ...
- linux下的C语言开发(网络编程)
http://blog.csdn.net/feixiaoxing/article/details/7259675 [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing ...
- ShadowMap渲染阴影方法及问题 【转】
ShadowMap基于的原理:SM算法是一个2-pass绘制算法,第一pass从光源视点绘制场景,生成SM纹理,第2pass从视点视图按常规方法绘制场景 从光源的位置观察场景,这时候我们看不到的地方就 ...
- 关于Gradle配置的小结
前言 使用 Android Studio 来开发 Android 工程的过程中,接触 Gradle 是不可避免的,比如配置签名.引入依赖等.那么 Gradle 到底是什么东西呢? Gradle 是一个 ...
- vue2.0 自定义 弹窗(MessageBox)组件
组件模板 src/components/MessageBox/index.vue <!-- 自定义 MessageBox 组件 --> <template> <div c ...
- Ansible 汇总
不错的博客:https://www.cnblogs.com/EWWE/p/8146083.html 修改文件权限: 首先需要 vi /etc/ansible/hosts (用pip install, ...
- ORACLE 查看表结构
select table_name from user_tables; //当前用户的表 select table_name from all_tables; //所有用户的表 select tabl ...