Count of integers

3.9

48 votes
Math Basic, Algorithms, Basic Math, Math
Problem

You are given a sequence A1,A2,,An. Determine the count of integers z (zA) that satisfies the following property :

z1i=1imodz=z1

Note: Your program must solve T independent test cases.

Input format

  • First line: T denoting the number of test cases
  • For each test case:
    • First line: n denoting the size of the sequence
    • Second line: n numbers A1,A2,...,An denoting the elements in the sequence

Output format

For each test case, print a number that indicates the count of integers in the sequence that satisfies the property. The output must be printed in a single line.

Constraints

1T10

1n105

2Ai108

Note: To know more about the  notation, read Capital_pi_notation.

 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Here the integers 3 and 7 satisfy the property :

2i=1imod3=2mod3=2  

6i=1imod7=6

 So count is 2.

Editor Image

?