Bzoj 2440 Total Square number (tolerant + MO-Black inversion + dichotomy)

Source: Internet
Author: User


2440: [Zhongshan 2011] Total Square number time limit: Sec Memory Limit: ten MB
Submit: 1673 Solved: 799
[Submit] [Status] [Discuss] 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

For 100% of the data is 1≤ki≤10^9, t≤50


Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=2440

Title Analysis: The title requirements of the K-squared factor number, we obviously can not find out the answer to query, the data range first think of is two, for the 1-n of the number of square factor we can use the tolerance theorem, take the total number minus 4 multiples (-N/4), minus 9 multiples (-N/9), But 36 is both a multiple of 4 and a multiple of 9, was reduced two times, to be added back (+N/36), so that the tolerance is out, the preceding sign and the number of square root after the corresponding Möbius function is the same, so the problem is simple, there is a point to explain the upper bound of the two points to open how big, This also affects the ratio of the MO to the function to open how much, we might as well assume that the K-squared factor is not more than 2k, specifically to prove that I do not, but the smallest square factor is 4, that is, every 4 number must have a square factor number, and because the square factor is larger, Can be yy out on average every four number has no more than two square factor number this conclusion, so the K no square factor number will not exceed 2k, (actually hit the table can also be verified), so the two upper bound to take 2k+1, Möbius function open sqrt (2e9) almost 5e4 appearance

1000ms over

#include <cstdio> #include <cstring> #include <algorithm> #define LL long longusing namespace Std;int    Const MAX = 5e4;ll Const INF = 2e9;int Mob[max], P[max];bool prime[max];void Mobius () {int pnum = 0;    Memset (Prime, true, sizeof (prime));    MOB[1] = 1;            for (int i = 2; i < MAX; i++) {if (Prime[i]) {p[pnum + +] = i;        Mob[i] =-1;            } for (int j = 0; J < pnum && I * p[j] < MAX; J + +) {Prime[i * P[j]] = false;                if (i% p[j] = = 0) {Mob[i * p[j]] = 0;            Break        } Mob[i * P[j]] =-mob[i];    }}}ll cal (int mid) {ll pos = 0;    for (int i = 1; I * I <= mid; i++) pos + = (LL) mob[i] * (Mid/(i * i)); return POS;}    int main () {Mobius ();    int T;    scanf ("%d", &t);        while (t--) {ll k;        scanf ("%lld", &k);        ll L = 1, R = 2 * k + 1; while (L <= R) {           ll mid = (L + r) >> 1;            if (Cal (mid) < K) L = mid + 1;        else R = mid-1;    } printf ("%lld\n", L); }}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 2440 Total Square number (tolerant + MO-Black inversion + dichotomy)

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.