All Tracks Math Number Theory Basic Number Theory-2 Problem

4141
Tag(s):

Easy-Medium, Mathematics, Number Theory

Problem
Editorial
Analytics

Link to Russian translation of problem

The statement of this problem is very simple: you are given a non-negative integer X. Whether it's divisible by 41?

Input
The first line contains one integer T - denoting the number of test cases. The following T lines contain 4 integers a[0], a1, c, n each and describe each test case:

Let's consider decimal representation of the number X as an array where a[0] is the leftmost (highest) digit. You are given a[0], a1 and each a[i] for 2 <= i <= n-1 can be found by formula:

a[i] = ( a[i - 1]*c + a[i - 2] ) modulo 10

Output
For each test case output YES if the corresponding integer is divisible by 41 and NO otherwise.

Constraints

  • T <= 2000
  • 1 <=N <= 50000
  • 0 <= a[0], a1, c < 10
SAMPLE INPUT
5
1 4 6 2
4 1 4 2
8 2 1 2
2 8 8 2
1 2 1 3
SAMPLE OUTPUT
NO
YES
YES
NO
YES
Explanation

Numbers: 14, 41, 82, 28, 123.

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

Code Monk (Number Theory - III)

OTHER PROBLEMS OF THIS CHALLENGE
Уведомления
View All Notifications

?