题目链接 : 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的更多相关文章

  1. 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 ...

  2. 「AtCoder Grand018B」Sports Festival(暴力)

    题目链接B - Sports Festival 题意 n(1~300)个人m(1~300)个活动,\(A_{ij}\)表示i第j喜欢的活动,每个人选择在举办的活动里最喜欢的,因此可以通过选择一些活动来 ...

  3. 新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial

    新巴巴运动网上商城 项目 快速搭建 教程 The new babar sports online mall project quickly builds a tutorial 作者:韩梦飞沙 Auth ...

  4. 5. Sports 体育运动

    5. Sports 体育运动 (1) Sport is not only physically challenging,but it can also be mentally challenging. ...

  5. OpenJ_POJ C16D Extracurricular Sports 打表找规律

    Extracurricular Sports 题目连接: http://acm.hust.edu.cn/vjudge/contest/122701#problem/D Description As w ...

  6. TZOJ 4007 The Siruseri Sports Stadium(区间贪心)

    描述 The bustling town of Siruseri has just one sports stadium. There are a number of schools, college ...

  7. 【OpenJ_POJ C16D】Extracurricular Sports(构造,找规律)

    题目求n个互不相同的数,满足其和为其lcm.我们把lcm看成一个线段,分割成长度不同的n份.当然分法有很多,我们只需要构造一个好想好写的.先分成两个二分之一,取其中一个二分之一再分成1/3和2/3,接 ...

  8. [HackerCup Round1 3] Winning at Sports (动态规划)

    题目链接:https://www.facebook.com/hackercup/problems.php?pid=688426044611322&round=344496159068801 题 ...

  9. ZOJ 3757 Alice and Bob and Cue Sports(模拟)

    题目链接 题意 : 玩台球.Alice 和 Bob,一共可以进行m次,Alice 先打.有一个白球和n个标有不同标号的球,称目标球为当前在桌子上的除了白球以外的数值最小的球,默认白球的标号为0.如果白 ...

  10. zoj 3757 Alice and Bob and Cue Sports 模拟

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3757 #include<cstdio> #incl ...

随机推荐

  1. arcgis andriod 加载影像

    MapView mMapView;......String rasterPath = Environment.getExternalStorageDirectory().getPath() + &qu ...

  2. Android view 数据缓存

    Android中经常需要用到view数据的缓存,比如我们希望EditText 在被切到别的界面的时候,输入的数据要仍保持不变. 参考代码: /* 缓存textview */ public class ...

  3. 设计模式——介绍与工厂模式(扁平管理模式VS职业经理人模式)

    本文主要对设计模式进行大概解说.特别是对工厂模式进行简明的解析: 一.设计模式的分类 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式. ...

  4. [LeetCode][Java] Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  5. 更改已经签名的app中的内容

    转载请说明出处http://blog.csdn.net/andywuchuanlong 记得上次在南昌中兴的一个项目中遇到过一个这种需求:一个app能够给多个渠道商去运营,渠道商推广出去能够获得对应的 ...

  6. 【POJ 3026】Borg Maze

    id=3026">[POJ 3026]Borg Maze 一个考察队搜索alien 这个考察队能够无限切割 问搜索到全部alien所须要的总步数 即求一个无向图 包括全部的点而且总权值 ...

  7. 指针初始化为NULL的作用

    关于空指针NULL.野指针.通用指针,首先说一下什么是指针,只要明白了指针的含义,你就明白null的含义了. 假设 有语句 int a=10;那么编译器就在内存中开辟1个整型单元存放变量a,我们假设这 ...

  8. Solaris磁盘配额

    磁盘配额:就跟汽车行驶速度一样.我们设定. 添加rq标志,使其支持配额功能. 命令:quota ,打开就是quotaon 对ZFS文件系统进行设置配额: 当设置quota=none 则可以取消配额设置 ...

  9. 日志打印longging模块(控制台和文件同时输出)

    在把日志写入文件的同时在控制台输出 示例代码如下: #coding=utf-8 import logging import time import os dir = os.path.dirname(o ...

  10. Java爬虫快速开发工具uncs的部署攻略

    写在前面 uncs是java快速开发爬虫的工具,简单便捷,经过大量版本迭代和生产验证,可以适用大多数网站,推荐使用. 一.基本用法 1.1 开发包获取 目前只能在公司内网maven服务器获取到 < ...