4141
Practice
3.9 (59 votes)
Approved
Easy
Math
Number theory
Open
Problem
56% Success 9314 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
12 votes
Tags:
EasyMathNumber TheoryNumber theory
Points:30
58 votes
Tags:
ApprovedEasyMathNumber theory
Points:30
19 votes
Tags:
AlgorithmsEuler's totient functionGreatest common divisorMathNumber TheorySieve