问题描述

3*3的矩阵内容。

1 2 3

2 4 6

3 6 9

即a[i][j](1<=i<=n,1<=j<=n)=i*j。

问一个这样n*n的矩阵里面,里面m出现的次数。

例如n为3,m为6.

那么出现的次数就是2

Input

输入正整数N,表示N例测试(N<=20)。接着输入n(n<=10^5),m(<=10^9)。

Output

对每组输入数据,输出m出现的次数。

Sample Input

2

3 6

3 3

Sample Output

2

2

#include <iostream>
#define N 100000
using namespace std; int main()
{
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int m;
cin >> m;
int cnt=;
for(int i=;i<=n;i++){
if(m%i== && m/i<=n)
cnt++;
}
cout << cnt << endl;
}
return ;
}

P.S.很多人把这个题想的太复杂。如果矩阵的每个数都要看,时间复杂度是10^10*2*10,肯定会超时。

我们仔细想下这个题目,每行最多只有一个数。如果第i行。如果能找到i*j==m并且j<=n,那么就可以。

每行判断m%i是否为0,m/i就是j如果<=n,那么那个数就是m。cnt++。

最新文章

  1. angular2系列教程(四)Attribute directives
  2. 数组中pop()和reverse()方法调用
  3. actor concurrency
  4. java selenium针对多种情况的多窗口切换
  5. HDU 3966 Aragorn&#39;s Story 树链剖分+树状数组 或 树链剖分+线段树
  6. vijos2001 xor-sigma
  7. cos
  8. 关于Windows下mysql忘记root密码的解决方法
  9. (二)Knockout - ViewModel 的使用
  10. 一种解决h5页面背景音乐不能自动播放的方案
  11. Java synchronized 关键字的实现原理
  12. Python-MongoDB的驱动安装、升级
  13. spring-cloud-sleuth 和 分布式链路跟踪系统
  14. [Linux] Configure iSCSI on Linux5 (both target and initiator)
  15. Python pyYAML模块
  16. (lower_bound)find the nth digit hdu1597
  17. Wilcoxon-Mann-Whitney rank sum test
  18. 修改MyEclipse取消默认工作空间
  19. JQuery为textarea添加maxlength
  20. RecyclerView 作为聊天界面,被键盘遮挡的解决办法

热门文章

  1. 用matplotlib绘制漫画风格的图表
  2. 经验分享:如何系统学习 Web 前端技术?
  3. Interllij IDEA 使用Git工具
  4. jQuery插件开发,jquery插件
  5. 【转载】CoordinatorLayout源码解析
  6. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana(分块)
  7. Python开发基础-Day4-布尔运算、集合
  8. codevs1033 蚯蚓的游戏问题 裸最小费用最大流,注意要拆点
  9. 【线段树+离散化】POJ2528-Mayor&#39;s posters
  10. bzoj 4627: [BeiJing2016]回转寿司