[2015HDU Multi-School League supplementary title]hdu 5297 Y sequence

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5297

Test instructions: give you a sequence of all positive integers, and then remove all the numbers that satisfy x^ (2~R) (x is all positive integers, r>=2 questions given), and ask you what the nth number of this sequence is now

Solution: First think of writing a function func (y), it can calculate the given number y is the number of numbers in the sequence, so that we can probably two answers ~ (in fact, the tle, we have to use the iterative method, of course, the iteration is also used this function)

So how to implement Func:

First, to get rid of all the numbers that satisfy x^2, we can use POW (y, 1/2) to calculate how many of the numbers that meet x^2 are below Y.

Then remove the satisfying x^3 and notice that the number of x^6 here has been removed two times, then we can do the repulsion so that Func realizes

After the implementation of the Func, the beginning of the two points, the results of various tle, iteration over the (specific code, the complexity of the sense of iteration is metaphysics ~)

1 /*2 * Problem:3 * AUTHOR:SHJWUDP4 * Created TIME:2015/8/3 Monday 14:44:485 * File name:233.cpp6 * State:7 * Memo:8  */9#include <iostream>Ten#include <cstdio> One#include <cstring> A#include <algorithm> -#include <cmath> -  the using namespacestd; -  - Long LongN; - intR; +vector<int>tmptable; -vector<int>table; + Long LongCalLong LongXLong LongPower) { A     returnPowDouble(x+0.5),1.0/power)-1; at } - voidinit () { - table.clear (); -      for(intI=0; i< (int) tmptable.size () &&-tmptable[i]<=r; i++) { -         intA=Tmptable[i]; -         inttmp=table.size (); in          for(intj=0; j<tmp; J + +) { -             intb=Table[j]; to             if(ABS (A*B) <= the) Table.push_back (A *b); +         } - Table.push_back (a); the     } * } $ Long LongFuncLong Longx) {Panax Notoginseng     if(x==1)return 0; -     Long Longres=x; the      for(intpower:table) { +         Long LongTmp=pow (Double(x+0.5),1.0/abs (Power))-1; A         if(power<0) res-=tmp; the         Elseres+=tmp; +     } -     returnres-1; $ } $ intMain () { - #ifndef Online_judge -Freopen ("inch","R", stdin); the //freopen ("Out", "w", stdout); - #endifWuyivector<int> Vis ( the,0); the      for(intI=2; i< the; i++) { -         if(vis[i]!=0)Continue; WuTmptable.push_back (-i); -          for(intJ=i+i; j< the; j+=i) { Aboutvis[j]=1; $         } -     } -     intT; -scanf"%d", &T); A      while(t--) { +scanf"%i64d%d", &n, &R); the init (); -         Long LongAns=n, tmp=-1; $          while(tmp!=N) { thetmp=func (ans); theans+=n-tmp; the         } theprintf"%i64d\n", ans); -     } in     return 0; the}
HDU 5297

[2015HDU Multi-School league title]hdu 5297 Y sequence

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.