码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 577A Multiplication Table

时间:2015-11-27 14:36:55      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

A. Multiplication Table

 
 

Let‘s consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.

You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.

Input

The single line contains numbers n and x (1 ≤ n ≤ 105, 1 ≤ x ≤ 109) — the size of the table and the number that we are looking for in the table.

Output

Print a single number: the number of times x occurs in the table.

Sample test(s)
Input
10 5
Output
2
Input
6 12
Output
4
Input
5 13
Output
0
Note

A table for the second sample test is given below. The occurrences of number 12 are marked bold.

技术分享

 1 #include<cstdio>
 2 #include<vector>
 3 #include<cmath>
 4 #include<queue>
 5 #include<map>
 6 #include<cstring>
 7 #include<algorithm>
 8 using namespace std;
 9 typedef long long ll;
10 typedef unsigned long long ull;
11 const int maxn=100005;
12 vector<int>prime;
13 int e[maxn],p[maxn],flag,ans,n,x;
14 void get_prim()
15 {
16     for(int i=2;i*i<maxn;i++)
17         for(int j=i+i;j<maxn;j+=i)
18             p[j]=1;
19         for(int i=2;i<maxn;i++)
20         if(!p[i])prime.push_back(i);
21 }
22 void resolve(int ob)//分解为质因子
23 {
24     memset(e,0,sizeof(e));
25     int num=prime.size();
26     for(int i=0;i<num;i++)
27     {
28         while(ob%prime[i]==0)ob/=prime[i],e[i]++;
29         if(ob==1)
30         {
31             flag=i;
32             break;
33         }
34     }
35 }
36 void dfs(int pro,int cur)//枚举约数
37 {
38     if(cur==flag+1)
39     {
40         int t=x/pro;
41         if(t<=n&&pro<=n)
42             ans++;
43         return;
44     }
45     for(int i=0;i<=e[cur];i++)
46         dfs(pro*pow(prime[cur]*1.0,i),cur+1);
47 }
48 int main()
49 {
50     get_prim();
51     while(scanf("%d%d",&n,&x)!=EOF)
52     {
53         ans=0;
54         resolve(x);
55         dfs(1,0);
56         printf("%d\n",ans);
57     }
58     return 0;
59 }

 

codeforces 577A Multiplication Table

标签:

原文地址:http://www.cnblogs.com/homura/p/5000278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!