---
{"category_name":"easy","problem_code":"MODEQUAL","problem_name":"Mod Equality","problemComponents":{"constraints":"- $1 \\leq T \\leq 10^4$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq A_i \\leq 2 \\cdot 10^9$\n- It is guaranteed that the sum of $N$ over all test cases does not exceed $10^6$.","constraintsState":true,"subtasks":"- 30 points : $1 \\leq R \\leq 10000$\n- 70 points : $1 \\leq R \\leq 10^9$\n","subtasksState":false,"inputFormat":"- The first line contains an integer $T$ - the number of test cases. Then $T$ test cases follow.\n- The first line of each test case contains an integer $N$ - the size of array.\n- The second line contains $N$ integers $A_1, A_2, \\ldots, A_N$ - the elements of the array.\n","inputFormatState":true,"outputFormat":"For each test, print one line containing an integer which denotes minimum number of operations performed to make all the elements equal.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"2\n3\n2 1 3\n3\n1 1 3\n","output":"3\n1\n","explanation":"In first test case, we can make all the elements equal by following operations:\n * Take $i = 1$ and $M = 2$ and do $A_1 := A_1 \\bmod 2 = 0$.\n * Take $i = 2$ and $M = 1$ and do $A_2 := A_2 \\bmod 1 = 0$.\n * Take $i = 3$ and $M = 3$ and do $A_3 := A_3 \\bmod 3 = 0$. \nAfter these $3$ operations we have all the elements equal to zero.\n \nIn second test case, we can perform following operation: \n * Choose $i = 3$ and $M = 2$ and do $A_3 := A_3 \\bmod 2 = 1$. \nAfter this operation all the elements are $1$.\n","isDeleted":false}}},"video_editorial_url":"https://youtu.be/2_naUVOD80w","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"vichitr","problem_tester":"aryanc403","date_added":"19-07-2021","tags":{"0":"ad","1":"basic","2":"cook131","3":"easy","4":"vichitr","5":"vichitr"},"problem_difficulty_level":"Easy","best_tag":"Ad Hoc","editorial_url":"https://discuss.codechef.com/problems/MODEQUAL","time":{"view_start_date":1627492504,"submit_start_date":1627492504,"visible_start_date":1627492504,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=MODEQUAL","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problems statements in [Mandarin Chinese](https://www.codechef.com/download/translated/COOK131/mandarin/MODEQUAL.pdf), [Russian](https://www.codechef.com/download/translated/COOK131/russian/MODEQUAL.pdf), [Vietnamese](https://www.codechef.com/download/translated/COOK131/vietnamese/MODEQUAL.pdf) and [Bengali](https://www.codechef.com/download/translated/COOK131/bengali/MODEQUAL.pdf) as well.
You are given $N$ non-negative integers $A_1, A_2, \ldots, A_N$. You are allowed to perform following operation any number of times:
- Choose any valid index $i$ ($1 \le i \le N$) and a positive integer $M>0$ and replace $A_i$ with $A_i\bmod M$. That is, replace $A_i$ with its remainder when divided by $M$, which is a value between $0$ and $M-1$, inclusive.
- $M$ does not need to be same between different operations.
Find the minimum number of operations to make all the array elements **equal**.
**Note:** Since the input and output are large, prefer using fast input-output methods.
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>