标签:
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.
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.
Print a single number: the number of times x occurs in the table.
10 5
2
6 12
4
5 13
0
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