346E - Doodle Jump - CodeForces Solution


math number theory *3000

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int T,a,n,p,h;
int calc(int a,int n,int p){
	int x=1ll*a*n/p;
	if (!x) return a>p-a*n?a:p-a*n;
	return calc(a-p%a,x-(1ll*a*n%p<(p/a-1)*a),a);
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d",&a,&n,&p,&h); a%=p;
		printf("%s\n",((1ll*a*n<p?a:calc(a,n,p))>h)?"NO":"YES");
	}
}
	   		 		  				    		 		  		  	


Comments

Submit
0 Comments
More Questions

Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef