# DCP-524: School Days Back to All Problems

Medium Math > Basic Math

bool IsOkay ( var x, var y ) { if( (x+y) == (x-y) ) return True; if( (x+y) == (x*y) ) return True; if( (x+y) == (x/y) ) return True; if( (x-y) == (x*y) ) return True; if( (x-y) == (x/y) ) return True; if( (x*y) == (x/y) ) return True; return False; } You are given a array( **Arr** ) of **N** integers. Find number of **pairs ( i, j )** possible such that ( **1 <= i < j <= N** ) and **IsOkay** ( Arr [ i ] , Arr [ j ] ) returns **True**. [ **one based** index array ] **Note**: Above division is floating point division. Input: ------ Input starts with an integer **T**, denoting the number of test cases. Each case contains **five** integers N, F, A, B and M. **N** is length of array, **F** is first element of array i.e Arr [ 1 ]. Then, use the recurrence below to generate Arr [ i ] for i = 2 to N: Arr [ i ] = ( A * Arr [ i-1 ] + B ) modulo M Constraints: ------- 1<=T<=100 1<=N<=10^6 0<=A,B<=10^9 1<=M<=10^9 0<=F<M Output: ------- For each test case print required answer. Sample Input ------------ 1 2 0 0 0 1 Sample Output ------------- 1

### Problem Limits

 Language Time Limit (seconds) C 3.00 C++ 3.00 C++14 3.00 C# 5.00 Go 5.00 Java 5.00 JavaScript 5.00 Objective-C 5.00 Perl 4.00 PHP 5.00 Python 5.00 Python3 5.00 Ruby 5.00 VB.Net 5.00

# 10/248

Solve/Submission

### Ranking

# User Language Timing
01 feodorv C 1.07s
02 pulak_ict_mbstu Cpp 1.40s
03 Robbinb1993 Cpp 1.44s
04 a_rahman Cpp 1.44s
05 emrul Cpp 1.59s
06 Towfiq379 Cpp 1.97s
07 kzvd4729 Cpp 2.26s
08 hrOarr Cpp 2.55s
Feedback