DCEPC804 - Totient Fever

no tags 

Another Totient problem by Ankur Sir J. He is madly in love with totient. Let’s see what he has prepared this time.

Recently he was studying integral properties of Quadratic functions. He found some interesting notions of real and complex numbers through Quadratic functions. But as you know he is a big totient fan, he mixed totient with quadratic functions this time and that resulted into a nice problem. He wants to find out if there exists a real root ‘x’ in the equation below:

Totient(a*x^2 + b*x + c) = k

Given ‘a’, ‘b’, ‘c’ and ‘k’, output “Yes” if a real root exists or “No” if no real root exists.

Input

First line contains T, the no. of test cases.

Each of the next T lines contains a, b, c and k.

Output

Output T lines, each for a single test case, containing either a “Yes” or a “No” corresponding to the test case.

Constraints

0 < T <= 100

0 < a <= 10^6

0 < b <= 10^6

0 < c <= 10^6

0 < k <= 10^6

b^2 >= 4*a*c

Example

Input:
2
1 4 3 4
1 21 11 10

Output:
Yes
Yes

hide comments
Min_25: 2014-05-09 11:31:04

@Lakshman
Since T is very small, another approach (which does not enumerate totient values) is faster for this problem.

[Lakshman]: 2014-05-09 10:43:51

@Min_25 amazing speed. Is there any direct formula or some ultra fast algorithm.

Flago: 2014-05-09 09:32:32

@SanchitK : I dunno if i can say that without being too "spoilly" but, n=4166250 is maximum value for T(n)=10^6 however T(n)=995328 admit n=5290740 as maximum.

SanchitK: 2014-03-27 21:17:57

for k=1000000, what is the maximum value of n whose totient is 1000000?

(Tjandra Satria Gunawan)(曾毅昆): 2012-12-11 18:49:50

@Ehor Nechiporenko: Congratulations :-D you're faster than me for this problem...

Ehor Nechiporenko: 2012-10-16 09:25:49

@Tjandra, unfortunantly you are not the fastest. But thanks for your INVPHI problem, it helped me to resolve this one ;-)

(Tjandra Satria Gunawan)(曾毅昆): 2012-09-27 15:10:59

Another approach, time: 0.3sec, woohoo! ;-)

(Tjandra Satria Gunawan)(曾毅昆): 2012-09-27 14:18:39

Finally AC, very nice problem :-)
Need 29 days for me to get the idea for solving this problem..
With efficient data structure and own idea/trick, AC in 1.3sec and use only 2.2MB of memory, and first place ;-D


Added by:dce coders
Date:2012-08-19
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:Own Problem