Sunteți pe pagina 1din 6

 PROBLEMS  STATUS  RANKS  DISCUSS  JOBS  sign in

Problems / classical / Divisibility Test Status Ranking

MATNUM - Divisibility Test


no tags

Problem statement is simple and straight forward . You will be given a non-negative
integer P of length N and you need to check whether it's divisible by Q ?

Integer P will be given in its decimal representation with P0 as leftmost digit and P1 as
second digit from left !

Rest of the digit can be generated from the formula :

Pi = ( 4*Pi-1 + Pi-2 ) modulo Q for 2 <= i <= N-1

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Input
The first line contains one integer T - denoting the number of test cases.

T lines follow each containing four integers P0 , P1 , Q and N !

Output
For each testcase output YES if the corresponding integer is divisible by Q and NO
otherwise.

Constraints
T <= 100000
0 < P0 , P1 , Q < 10
0 < N <= 1018

Example

Input:
4

1 4 2 2

1 4 2 1

4 2 3 2
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
3 4 7 3

Output:

YES

NO

YES

NO

Explanation
Value of P is 14, 1, 42, 345 in respective cases !

 Submit solution!

hide comments
Bhuvnesh Jain: 2015-11-30 21:56:35

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
@adarsh kumar, can you please tell me why I am getting WA as I have tested by
code on random test cases with brute solution as well and it was working fine...
my last solution contains comments showing the implementation details and
logic of solution as well.

(reply) => Your last submission has wrong answers for 1300 cases (approx.) for
n<100 itself ! I guess you can easily find them :)

Last edit: 2015-11-30 22:54:27


Bhuvnesh Jain: 2015-11-30 16:46:44
Are the submissions being rejudged?

(reply) => Did that already . You still have WA (you can check with a brute) !

Last edit: 2015-11-30 17:42:43


Bhuvnesh Jain: 2015-11-30 13:57:04
test files are not according to the constraints.
For q>=10, assertion fails and I am getting sigabrt error

(reply) => thanks for pointing it out . Test data are rectified now. Sorry for the
inconvenience caused !

Last edit: 2015-11-30 15:35:04

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
 Submit solution!

Added by: Adarsh kumar


Date: 2015-11-29
Time limit: 1s-1.5s
Source limit: 50000B
Memory limit: 1536MB
Cube (Intel Pentium G860
Cluster:
3GHz)
Languages: All
Resource: Own problem

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
About | Tutorial | Tools | Clusters | Credits | Jobs | API
RSS

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com

S-ar putea să vă placă și