Test instructions
Give you an n and an R, and find out what the nth item of the y sequence is.
The so-called Y sequence is, starting from 1, to remove the number that can be expressed as a^b (2<=b<=r), the sequence of the composition
such as r=2
The sequence is: 2,3,5,6,7,8,10,11,12,13,14,15,17 ....
Ideas:
We should be able to think of the need for a function fun (x) to find out how many of the 1~x within the Y sequence
This is not difficult, we can use the principle of the repulsion, through the number of primes within 63 to calculate, and do up to three times, because 2*3*5*7>63
And then there's a very magical way, and this method is a special second.
is the iterative approach.
Suppose we now ask for the number of the nth y sequence, first assuming that Nth is N, then let's ask Fun (n) =tep
TEP represents the number of tep in the y sequence, and there are n-tep on the other.
So we'll ask for fun next time (n+ (n-tep)) to see if it equals N, so we continue to iterate
Until Tep==n.
Why is this right?
Because we only add the missing number each time, in fact, it is assumed that if the addition of these numbers will not be rejected, then the answer is.
So it is impossible to add more than the correct answer.
Then because it is obviously very discrete, because it is a secondary level, the number of iterations is not much.
Code:
#include "stdio.h" #include "algorithm" #include "string.h" #include "iostream" #include "queue" #include "map" #include " Vector "#include" string "#include" Cmath "using namespace std; #define LL __int64int ss[]= { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67};ll n;int r;int used[22];ll dfs (int ii,int x,int k,int tep,double KX) {if (x==k) {return (int) (POW (kx+0.5,1.0/tep)-1);//note +0.5 control accuracy! } if (tep>63) return 0; ll Ans=0; for (int i=ii+1, i<18; i++) {if (Ss[i]>r | | tep*ss[i]>63) break; if (used[i]==0) {used[i]=1; Ans+=dfs (I,X+1,K,TEP*SS[I],KX); used[i]=0; }} return ans; ll Fun (ll X) {ll ans=0; for (int i=1; i<5; i++) {memset (used,0,sizeof (used)); if (i%2) Ans+=dfs ( -1,0,i,1,x*1.0); else Ans-=dfs ( -1,0,i,1,x*1.0); } return x (ans+1);} int main () {int t; cin>>t; while (t--) {scanf ("%i64d%d", &n,&r); ll Ans=n; WhilE (1) {ll tep=fun (ans); if (tep==n) break; Ans+=n-tep; } printf ("%i64d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Multi-school 2015.01.1010 tolerance + iteration] hdu 5297 Y sequence