题目链接 : 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那部分列;

可能说的不太清楚,或者我理解不深,请看代码自己想一想或许就懂了。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cctype>
  4. #include <cmath>
  5. #include <set>
  6. #include <map>
  7. #include <list>
  8. #include <queue>
  9. #include <deque>
  10. #include <stack>
  11. #include <string>
  12. #include <vector>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <stdlib.h>
  16. #include <time.h>
  17.  
  18. using namespace std;
  19. typedef long long LL;
  20. const int INF=2e9+1e8;
  21. const int MOD=1e9+;
  22. const int MAXSIZE=1e6+;
  23. const double eps=0.0000000001;
  24. void fre()
  25. {
  26. freopen("in.txt","r",stdin);
  27. freopen("out.txt","w",stdout);
  28. }
  29. #define memst(a,b) memset(a,b,sizeof(a))
  30. #define fr(i,a,n) for(int i=a;i<n;i++)
  31.  
  32. const int MAXN=5e4+;
  33. int arr[MAXN],fac[MAXN],myindex;
  34. void init(int k)
  35. {
  36. myindex=;
  37. for(int i=;i<=sqrt(k);i++)
  38. if(k%i==) fac[myindex++]=i,fac[myindex++]=k/i;
  39. }
  40. int main(int argc,char *argv[])
  41. {
  42. int ncase,k;
  43. scanf("%d",&ncase);
  44. while(ncase--)
  45. {
  46. LL n,m;
  47. scanf("%lld%lld%d",&n,&m,&k);
  48. init(k);
  49. sort(fac,fac+myindex);
  50. LL ans=;
  51. for(int i=;i<myindex;i++)
  52. {
  53. int a=fac[i],b=k/fac[i];
  54. arr[i]=m/b; // 列数
  55. for(int j=;j<i;j++)
  56. if(a%fac[j]==) arr[i]-=arr[j];
  57. //排除一些列数 : 如果 行号成倍数;就说明重复了;所以有 容斥
  58. ans+=n/a*(arr[i]);
  59. }
  60. printf("%lld\n",ans);
  61. }
  62. return ;
  63. }
  64.  
  65. /**************************************************/
  66. /** Copyright Notice **/
  67. /** writer: wurong **/
  68. /** school: nyist **/
  69. /** blog : http://blog.csdn.net/wr_technology **/
  70. /**************************************************/

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. javascript 函数初探 (六)--- 闭包初探#3

    相关定义与闭包: 实际上,每个函数都可以被认为是一个闭包.因为每个函数都在其所在域(即该函数的作用域)中维护了某种联系. 但在大多数的时候,该作用于在函数体内被执行完之后就被自行销毁了.---除非发生 ...

  2. openfire Android学习(三)----会议室创建、加入以及查询会议室中所有成员等

    openfire 中的会议室不像QQ群一样,不能保存那些离线用户,加入会议室后,一旦断开连接,就会离开会议室. 虽然如此,但如果要实现也不是不可能,我们可以自己做后台来保存,有兴趣的可以去试着实现一下 ...

  3. Android -- 开机启动无界面后台程序

    简单的说,这是一个没有界面的后台运行的应用程序 而且,还有一功能:开机自启动,启动运行一个服务 程序结构非常简单,两个类,一个是service的扩展类,一个是BroadcastReceiver扩展类 ...

  4. Caused by: java.io.FileNotFoundException: rmi_keystore.jks (没有那个文件或目录)

    解决方法:修改jmeter.properites: server.rmi.ssl.disable=true,关闭ssl功能 参考: https://blog.csdn.net/nielinqi520/ ...

  5. Flash中如何使用滤镜

    使用滤镜 应用或删除滤镜 复制和粘贴滤镜 为对象应用预设滤镜 启用或禁用应用于对象的滤镜 启用或禁用应用于对象的所有滤镜 创建预设滤镜库 对象每添加一个新的滤镜,在属性检查器中,就会将其添加到该对象所 ...

  6. hdu 1548

    A strange lift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  7. best-time-to-buy-and-sell-stock系列——先买入后卖出股票的最大值

    1. Say you have an array for which the i th element is the price of a given stock on day  i . If you ...

  8. idea自动注入和自动编译

    ---恢复内容开始--- 自动编译也就是时时编译,当我们写错代码的时候,idea能够马上报错,这个是不错的功能. 安装操作看下图: 下面这个功能的作用就是,如果你不修改的话,你的项目可以正常运行,但是 ...

  9. HDU1009_FatMouse&#39; Trade【贪心】【水题】

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. IDEA搭建Android wear开发环境,Android wear,I&#39;m comming!

    随着google公布了android wear这个东西.然后又有了三星的gear,LG的G watch以及moto 360,苹果由公布了apple watch.未来可能在智能手表行业又有一场战争. 当 ...