Bzoj2440: [Zhongshan City, 2011] Full shard count

Source: Internet
Author: User
2440: [Zhongshan City 2011] full quota time limit: 10 sec memory limit: 128 MB
Submit: 883 solved: 425
[Submit] [Status] Description

Small X is fond of data. But the strange thing is that he hates the full limit. He thinks
Numbers seem quite uncomfortable. As a result, he also hates all positive integers that are multiples of the total number of integers. However
This does not affect his love for other data.
This is the birthday of John. John wants to give him a birthday gift. Of course, he cannot send one.
A small x annoying number. He lists all the numbers that small X does not hate, and then selects the k Number
Small X. Little X was very happy to accept it.
However, small W cannot remember which number is sent to small X. Can you help him?

Input

Contains multiple groups of test data. The first line of the file has an integer T, indicating the test
The number of data groups.
Each line from line 2nd to line t + 1 has an integer Ki, which describes a set of data. The meaning is described in the topic.

Output

Contains t rows and answers to each group of data respectively. Line I outputs the corresponding
The Ki number is not a positive integer multiple of the number of complete integers.

Sample input4
1
13
100
1234567 sample output1
19
163
2030745 hint

For 100% of the data, 1 ≤ Ki ≤ 10 ^ 9

, T ≤ 50

Source

Question:

Binary + Determination

The problem is converted to how to determine the number of <= N is not a positive integer multiple of the number of workers.

Obviously, we only need to consider the multiples of the square of the prime number, and because there are duplicates, we need to use the Mobius function for calculation. This is obvious.

Code:

 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #include<string>12 #define inf 100000000013 #define maxn 20000014 #define maxm 500+10015 #define eps 1e-1016 #define ll long long17 #define pa pair<int,int>18 #define for0(i,n) for(int i=0;i<=(n);i++)19 #define for1(i,n) for(int i=1;i<=(n);i++)20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)22 using namespace std;23 inline int read()24 {25     int x=0,f=1;char ch=getchar();26     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}27     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}28     return x*f;29 }30 int p[maxn],mu[maxn];31 ll n;32 bool check[maxn];33 void get()34 35 {36 37     int tot=0;38 39     mu[1]=1;40 41     for2(i,2,maxn)42 43     {44 45         if(!check[i])p[++tot]=i,mu[i]=-1;46 47         for1(j,tot)48 49          {50 51              int k=p[j]*i;52 53              if(k>maxn)break;54 55             check[k]=1;56 57             if(i%p[j])mu[k]=-mu[i];else {mu[k]=0;break;}58 59          }60 61     }62 63 }64 inline bool test(ll x)65 {66     ll t=0;67     for1(i,(int)sqrt(x))t+=mu[i]*(x/(i*i));68     return t>=n;69 }70 int main()71 {72     freopen("input.txt","r",stdin);73     freopen("output.txt","w",stdout);74     get();75     int cs=read();76     while(cs--)77     {78         n=read();ll l=1,r=2*n,mid;79         while(l<=r)80         {81             mid=(l+r)>>1;82             if(test(mid))r=mid-1;else l=mid+1;83         }84         printf("%lld\n",l);85     }86     return 0;87 }
View code

 

Bzoj2440: [Zhongshan City, 2011] Full shard count

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.