Title Description
Given $ m $ distinct positive integers $ a_1, a_2, ..., a_m $, $ 0 to the request for $ m $ $ $ k $ each calculation, a positive number in the interval $ [1, n] $ li a is an integer divisor of $ $ $ k $ exactly in number.
Input Format
The first line contains two positive integers $ n, m $, respectively, and the size of the interval range $ A $ array.
The second line contains $ m $ distinct positive integers $ a_1, a_2, ..., a_m $, $ A $ array represents.
Output Format
$ M + 1 $ output lines, each an integer, wherein the first output line $ I $ $ k = i $ answer.
Sample
Sample input 1:
10 3
4 6 7
Sample output 1:
4
4
1
1
Sample input 2:
5 1
8
Sample Output 2:
2
3
Data range and tips
answer
To explain the meaning of problems (when the exam questions for half an hour before reading read ......), to this problem is to require $ [1, n] $ how much the number is $ a_1 \ sim a_m $ in $ 0 $ number about about the number, the number of $ 1 $ number of ......
Then consider how we should do.
We can enumerate only $ 1 \ sim \ sqrt {a_i} $ can be drawn about the number of all $ a_i $, and consider how storage.
My approach is to use the $ map $, storing each number about a divisor of several numbers $ a_1 \ sim a_i $ in.
Then we stored directly answer, set up an array $ sum [j] $ represent $ a_1 \ sim a_i $ is the number of divisors of which $ j $ number.
Whenever sweep times about a number just to $ sum [mp [j]] -; mp [j] ++; sum [mp [j]] ++ $ to.
Time complexity: $ \ Theta (m \ times \ sqrt {a_i}) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
using namespace std;
int n,m;
int sum[201];
map<int,int> mp;
int main()
{
scanf("%d%d",&n,&m);
sum[0]=n;
for(int i=1;i<=m;i++)
{
int x;scanf("%d",&x);
for(int j=1;j*j<=x&&j<=n;j++)
if(!(x%j))
{
sum[mp[j]]--;
mp[j]++;
sum[mp[j]]++;
if(j*j!=x&&x/j<=n)
{
sum[mp[x/j]]--;
mp[x/j]++;
sum[mp[x/j]]++;
}
}
}
for(int i=0;i<=m;i++)printf("%d\n",sum[i]);
return 0;
}
rp ++