Topic Portal (internal title 40)
Input Format
The first line: two positive integers $ n $, $ m $.
Output Format
The first line: an integer value representing the expression.
Sample
Sample input 1:
4 5
Sample output 1:
0
Sample Input 2:
799 8278
Sample Output 2:
-11
Data range and tips
answer
For each $ i $, its contribution is its ability to answer a few numbers with $ 1 \ sim m $ is obtained by multiplying a perfect square.
Obviously we need to enumerate the $ i $, then $ \ Theta (1) $ count contributions.
So this time there are two cases:
$ \ Alpha.i $ is a perfect square, this time we only required a $ 1 \ sim m $ has several perfect square, and this number is $ \ sqrt m $.
$ \ Beta.i $ is not a square, is well known, perfect square $ \ times $ $ $ = perfect square perfect squares. So consider the decomposition $ i $, will be broken down into $ p_1 \ times p_2 \ times ... \ times q $, where $ p $ is a perfect square, $ q $ non-perfect square, we request that $ q \ times j $ a few are a perfect square, and this number is the $ \ sqrt {\ frac {m} {q}} $.
Pretreatment out of every $ I $ $ q $, to $ \ Theta (1) $ calculated contribution.
Time complexity: $ \ Theta (n) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
using namespace std;
int n;
long long m;
int cnt[10000001];
bool pfs[10000001];
int ans;
int main()
{
scanf("%d%lld",&n,&m);
for(int i=1;i*i<=n;i++)
{
for(int j=1;i*i*j<=n;j++)
cnt[i*i*j]=j;
pfs[i*i]=1;
}
int sqr=sqrt(m);
for(int i=1;i<=n;i++)
if(pfs[i])
{
if(sqr&1)ans--;
else ans++;
}
else
{
if((int)sqrt(m/cnt[i])&1)ans--;
else ans++;
}
printf("%d",ans);
return 0;
}
rp ++