brucewayne123's blog

By brucewayne123, history, 8 years ago, In English

all the submissions are in queue since last 3-4 hours. please look forward to it. i hope today's contest is rated!! good luck evryone!

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it

By brucewayne123, history, 8 years ago, In English

hi everyone! i was trying this problem HENRY:- Henry and Lost Ranges

Henry is a curious little boy. He likes to play around with numbers. One day, he defined a fun ction f for natural numbers such that: f(X) = largest prime factor of X , where X > 1 For example: f(2) = 2

f(3) = 3

f(75) = 5

Now, Henry selected two integers A and B ( A ≤ B ) and counted all numbers X between A and B (both inclusive) such that f(X) = K . He found out that there are N such numbers. After that Henry went for playing. When he returned home, he found out that he had forgotten the upper limit of range i.e. the integer B . However, he remembers all other numbers i.e. A , K and N .

Henry wants to find out B as soon as possible. Can you help him finding it ?

Note:

● If there are multiple possible values of B , output the least value out of those.

● It is assured that the input will be in such a way that final value of B will be within the range of long long int .

Input

First line of input contains T , the number of test cases. The only line of each test case contains three integers A , K and N .

Output

For each test case, output a single line containing the integer B .

Constraints

● 1 ≤ T ≤ 5

● 2 ≤ A ≤ 10 9

● 2 ≤ K ≤ 11 and K is a prime number

● 0 ≤ N ≤ 152319

Example

Input:

5 3 2 4

5 3 4

4 5 4

5 7 4

3 11 4

Output:

32

18

20

28

44

Explanation

In the first case, least value of B such that there are exactly 4 numbers having largest prime factor as 2 in range [3,B] will be 32 (the 4 numbers are 4, 8, 16, 32 ).

In the second case, least value of B such that there are exactly 4 numbers having largest prime factor as 3 in range [5,B] will be 18 (the 4 numbers are 6, 9, 12, 18 ).

In the third case, least value of B such that there are exactly 4 numbers having largest prime factor as 5 in range [4,B] will be 20 (the 4 numbers are 5, 10, 15, 20 ).

In the fourth case, least value of B such that there are exactly 4 numbers having largest prime factor as 7 in range [5,B] will be 28 (the 4 numbers are 7, 14, 21, 28 ).

In the fifth case, least value of B such that there are exactly 4 numbers having largest prime factor as 11 in range [3,B] will be 44 (the 4 numbers are 11, 22, 33, 44 ).

my solution:- http://pastebin.com/VccNHSwz since k is <= 11 hence we have primes 2,3,5,7,11 only.. for a particular k i need to check only the numbers formed with combinations of all prime numbers<=k for example.. if k=5 then 2^a*3^b*5^c where c>=1 and a>=0 and b>=0.. so i precomputed all such numbers for all k in <=100000000 then i applied lower_bound to find the least b i am getting wrong answer although i think i have handled overflows correctly! please someone help me understand my mistake! PS:- code is lengthy because but very easy to understand

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it

By brucewayne123, history, 8 years ago, In English

problem:- https://www.hackerearth.com/practice/data-structures/advanced-data-structures/segment-trees/practice-problems/algorithm/shooting-range/description/ can anybody help me understand the code given in the editorial? i am not able to understand the logic used in this problem...

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By brucewayne123, history, 8 years ago, In English

http://www.spoj.com/problems/SPCO/ i was trying to solve this problem but couldnt think of any approach which would pass.. please help..

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By brucewayne123, history, 8 years ago, In English

problem link:- : http://mirror.codeforces.com/problemset/problem/552/D hello everyone! i am trying this problem on counting triangles with non zero area.. my approach is to represent a line segmnet between every 2 pair of points by the value (slope,constant) and using a map i am able to count how many points lie on this line segment reprsented by y=mx+c; for this i have used a set inside a map to avoid duplicacy and also for line segment with infinte slope i have used a seperate map.. after that i am simply subtracting the triangles from every line segment for total (NC3). i cant figure out the reason for wrong answer.. please help.. my submission:- http://mirror.codeforces.com/contest/552/submission/19069857

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By brucewayne123, history, 8 years ago, In English

problem link:- http://mirror.codeforces.com/problemset/problem/221/D i have used mo's algorithm and my complexity fits in given time limit.. but still i am getting TLE on test 5.. please help.. my submission:- http://mirror.codeforces.com/contest/221/submission/18995087

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By brucewayne123, history, 8 years ago, In English

https://code.google.com/codejam/contest/5254486/dashboard#s=p2 i am unable to solve the large subtask of this problem.. i solved the small one using brute force.. please help me understand the logic behind this problem.. thanks.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By brucewayne123, history, 9 years ago, In English

http://mirror.codeforces.com/problemset/problem/543/A hello! i was trying doing this problem in a top down manner.. but i am not able to calculate all the distinct ways.. for example.. if we have v1=1,v2=2,v3-0 then we can add 6 ways to answer by rearranging them but my code adds this just once.. also i am not getting why my recursion is going wrong.. please help me with it.. here is my implementaion without memoising.. https://ideone.com/rUtBD7 i have read the editorial which is explained nicely but it would be nice if someone corrects me in my top down approach.. thanks..

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By brucewayne123, history, 9 years ago, In English

http://mirror.codeforces.com/problemset/problem/437/D i was trying this problem but i dont know why i am getting wrong answer on test 7.. my code outputs some negative value(maybe an overflow error but i checked and wasnt able to found one). please someone look through my code and help.. my submission :- http://mirror.codeforces.com/contest/437/submission/18170970 PS:- i matched my solution with some accepted one and my logic is same.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it