"Math" full square number

Source: Internet
Author: User

2440: [Zhongshan 2011] Total Square number time limit:10 Sec Memory limit:128 MB
submit:3015 solved:1455 Description

Small X likes to count since childhood. But strangely enough, he hated the total square number. He thinks these
The numbers look very unpleasant. As a result, he also hates the number of positive integer multiples of the total squared number. However
This does not affect his love for other numbers at all.
This day is small x's birthday, small W wants to send a number to him as a birthday present. Of course he can't send a
A little x nasty number. He listed all the small x not annoying number, and then selected the number of K sent to the
Small x. Little X was happy to accept it.
But now little W can't remember which number is given to the small x. Can you help him?

Input

Contains multiple sets of test data. The first line of the file has an integer T, which indicates the test
The number of groups of data.
Lines 2nd to t+1 each line has an integer ki, which describes a set of data, meaning as described in the topic.

Output

Contains t lines, respectively, to answer each group of data. The first line outputs the corresponding
The first ki is not a number of positive integer multiples of the complete square number.

Sample Input4
1
13
100
1234567Sample Output1
19
163
2030745HINT

1≤ki≤10^9 for 100% of data

Analysis of test questions:

The question is simply to ask for the K-squared factor number (not the number of full square multiples)

Then only the number of K single-factor indices not exceeding 1 will be solved.

So we can double this number, and then every time we judge it in the position of the number that fits the requirement.

So how do you judge where it is?

We just need to get rid of all the ≤n i^2.

Then we use the repulsion principle to deal with repetitive

But the time complexity of the repulsion principle is unacceptable, so you can consider the function of the MO-

(See: http://www.cnblogs.com/wxjor/p/5933213.html)

The final output two points out of the answer can be, the topic is not difficult

The code is as follows:

#include <iostream> #include <cstring> #include <cstdio> #include <cmath>using namespace std; Long long Prime[100001],miu[100001],mark[100001];long long Tot;long long m;void eular () {miu[1]=1;mark[1]=1;for (long Long i=2;i<=100000;i++) {if (!mark[i]) {prime[++tot]=i;miu[i]=-1;} For (long long j=1;j<=tot;j++) {if (i*prime[j]>100000) break;mark[i*prime[j]]=1;if (i%prime[j]==0) {miu[i*prime[ J]]=0;break;} else miu[i*prime[j]]=-miu[i];}} return;} A long long check (long long k) {Long long tmp=sqrt (k); Long long ret=0;for (long long i=1;i<=tmp;i++)    ret+=miu[i]* (k/( I*i)); return ret;} Long Long search (long long L,long long R) {while (l+1<r) {Long long mid= (l+r)/2;long long Tmp=check (mid); if (tmp<m) l=m Id;else R=mid;} return R;} Long Long T;int main () {eular (); Cin>>t;while (t--) {cin>>m;    Cout<<search (0,2*m) <<endl;}}

  

"Math" full square number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.