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!

# | User | Rating |
---|---|---|

1 | tourist | 3979 |

2 | Benq | 3623 |

3 | MiracleFaFa | 3604 |

4 | Radewoosh | 3545 |

5 | maroonrk | 3534 |

6 | slime | 3511 |

7 | greenheadstrange | 3430 |

8 | ecnerwala | 3342 |

9 | sunset | 3338 |

10 | xtqqwq | 3331 |

# | User | Contrib. |
---|---|---|

1 | YouKn0wWho | 210 |

2 | Monogon | 200 |

3 | Um_nik | 193 |

4 | awoo | 191 |

5 | -is-this-fft- | 184 |

6 | sus | 177 |

7 | Errichto | 175 |

8 | antontrygubO_o | 173 |

9 | maroonrk | 168 |

10 | SecondThread | 167 |

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

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/23/2022 21:44:06 (h3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|