Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

# Mod Equality CodeChef Solution

## Mod EqualityCodeChef Solution in C++17

``````#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x)   (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()
#define pb  push_back
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
// freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
ll tess;
cin >> tess;
while(tess--){
ll i,j,n,m,k;
cin >> n;
ll p[n];
for(i=0;i<n;i++){
cin >> p[i];
}
sort(p,p+n);
ll flag=0,ans=0;
ll mn=p[0];
for(i=0;i<n;i++){
if(p[i]!=mn){
if(p[i]<=2*mn){
flag=1;
break;
}else{
ans++;
}
}
}
if(flag) cout << n << "\n";
else cout << ans << "\n";
}
}``````

## Mod Equality CodeChef Solution in C++14

``````#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll solve(){
ll n;
cin>>n;
vector<ll>v(n);
for(ll i=0; i<n; i++) cin>>v[i];
sort(v.begin(),v.end());
ll mn=v[0]; bool f=1;
ll ans=n;
for(ll i=0; i<n; i++){
if(mn==v[i]) ans-=1;
else{
ll mx_pos=v[i]%2==0?(v[i]/2)-1:v[i]/2;
if(mx_pos<mn){
f=0; break;
}
}
}
if(!f) return n;
return ans;
}
int main() {
int t;
cin>>t;
while(t--){
cout<<solve()<<endl;
}
// your code goes here
return 0;
}``````

## Mod Equality CodeChef Solution in PYTH 3

``````# cook your dish here

from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().strip().split()))
m=min(a)
flag=0
for i in a:
if i-m<=m and m!=i:
flag=1
break
if flag==1:
print(n)
else:
print(n-a.count(m))``````

## Mod Equality CodeChef Solution in C

``````
#include <stdio.h>
typedef long long int ll;

ll cmpfunc (const void * a, const void * b) {
return ( *(ll*)a - *(ll*)b );
}

void me()
{
ll n;
scanf("%lld",&n);
ll ak[100003];

for(ll i=0;i<n;i++)
{
scanf("%lld",&ak[i]);

}

qsort(ak,n, sizeof(ll), cmpfunc);

ll a=ak[0],co=0,c=n;
if(n==1)
{
printf("0\n");
return;
}
ll b=a;
for(ll i=0;i<n;i++)
{
if(ak[i]!=a)
{
b=ak[i];
break;
}co++;
}

if(b-a!=1&&b!=a)
{
ll k=b-a;
ll d=b%(k);
if(a==d)
c=c-co;

}
if(b==a)
{
printf("0\n");
return;
}

printf("%lld\n",c);
}
int main()
{
ll t;
scanf("%lld",&t);
for(ll i=0;i<t;i++)
me();

return 0;
}``````

## Mod Equality CodeChef Solution in JAVA

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}

int ni() {
return Integer.parseInt(next());
}
int[] iArray0(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=ni();
return a;
}
int[] iArr1(int n){
int[] ar = new int[n + 1];
for(int i = 1; i <= n; i++) ar[i] = ni();
return ar;
}
long[] lArray0(int n){
long[] ar = new long[n];
for(int i = 0; i < n; i++) ar[i] = nl();
return ar;
}

long[] lArr1(int n){
long[] ar = new long[n + 1];
for(int i = 1; i <= n; i++) ar[i] = nl();
return ar;
}
long nl() {
return Long.parseLong(next());
}
}
static long mod=1000000007;
public static void main (String[] args) throws java.lang.Exception
{

FastScanner  sc = new FastScanner();
PrintWriter out=new PrintWriter(System.out);
int tc = sc.ni();
for(int t=0; t<tc; t++){
// write code
int n= sc.ni();
long a[]= sc.lArray0(n);
Arrays.sort(a);
int ans=0;
for(int i=1; i<n; i++){
if(a[i]<=2*a[0] && a[i]!=a[0]){
ans=n;
break;
}
else if(a[i]>2*a[0]){
ans=n-i;
break;
}
}
out.println(ans);
}
out.close();
}
// helper functions
//DisjointSet
static class DisjointSet{
int[] parent, rank;

DisjointSet(int n){
this.parent = new int[n];
this.rank = new int[n];
for(int i = 0; i < n; i++) this.parent[i] = i;
}

int find(int x){
if(x != parent[x]) parent[x] = find(parent[x]);
return parent[x];
}

boolean equiv(int x, int y){
return find(x) == find(y);
}

void union(int x, int y){
int xRoot = find(x), yRoot = find(y);

if(xRoot == yRoot) return;

if(rank[xRoot] < rank[yRoot]){
parent[xRoot] = yRoot;
}else if(rank[yRoot] < rank[xRoot]){
parent[yRoot] = xRoot;
}else{
parent[xRoot] = yRoot;
rank[yRoot]++;
}
}
}

public static int lower_bound(ArrayList<Integer> ar,int lo , int hi , int k)
{
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get(mid) <k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}

public static int upper_bound(ArrayList<Integer> ar,int lo , int hi, int k)
{
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get(mid) <=k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}

static String  decimalToFraction(double number)
{

double intVal = Math.floor(number);
double fVal = number - intVal;
final long pVal = 1000000000;
long gcdVal = gcd(Math.round(
fVal * pVal), pVal);

long num = Math.round(fVal * pVal) / gcdVal;
long deno = pVal / gcdVal;
String ans= num+"/"+deno;
return ans;

}
static boolean isPrime(long N)
{
if (N<=1)  return false;
if (N<=3)  return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}

static  long pow(long a,long b)
{
long mod=1000000007;
long pow=1;
long x=a;
while(b!=0)
{
if((b&1)!=0)pow=(pow*x)%mod;
x=(x*x)%mod;
b/=2;
}
return pow;
}

static long toggleBits(long x)//one's complement || Toggle bits
{
int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;

return ((1<<n)-1)^x;
}

static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}

static long fact(long N)
{
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}

private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
}``````

## Mod Equality CodeChef Solution in PYPY 3

``````for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
dct = dict()
for x in arr:
if x in dct:
dct[x] += 1
else:
dct[x] = 1
b=list(dct.keys())
if len(b)==1:
print(0)
continue
if 0 in b:
print(n-dct[0])
else:
flag = 1
ct = 0
p = min(b)
for x in b:
if x!=p:
if x> 2 * p:
ct += dct[x]
else:
flag = 0
break
if flag:
print(ct)
else:
print(n)``````

## Mod Equality CodeChef Solution in PYTH

``````t = int(raw_input())
for i in range(t):
N = int(raw_input())
st = raw_input().split()
A = []
for x in st:
A.append(int(x))
# endfor x
A.sort()
r = 0
if A[0] != A[-1]:
n = A[0]
p = 1
while A[p] == n:
p += 1
# endwhile
if A[p] > 2*n:
r = N-p
else:
r = N
# endif
# endif
print r
# endfor i
``````

## Mod Equality CodeChef Solution in NODEJS

``````process.stdin.resume();
process.stdin.setEncoding('utf8');

// your code goes here
// your code goes here
let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

function readLine() {
return inputString[currentLine++];
}

function main() {
const T = parseInt(inputString.shift(), 10);

for(let i=0; i<T; i++){
let N = parseInt(inputString.shift());
let arr = inputString.shift().trim().split(' ').map(x => parseInt(x));

let hashMap = {}
for(let i=0;i<N;i++){
if(!hashMap[arr[i]])
hashMap[arr[i]] = 0;
hashMap[arr[i]]++;
}
let arr2 = Object.keys(hashMap);
var min = Math.min(...arr2);

let min2 =  secondMin(arr2, min+'')

// console.log(`min1 \${min} min2 \${min2}`)

if((hashMap[2]  && hashMap[1] ) || (hashMap[0])) {
console.log(arr.length - (hashMap[0] || 0));
}
else if(min2 <= 2 * min){
console.log(arr.length);
}
else{
console.log(arr.length - hashMap[min]);
}

}
}

function secondMin(arr , min){
// console.log(arr);
arr.splice(arr.indexOf(min), 1);
// console.log(arr);
return Math.min.apply(null, arr);
};

``````

## Mod Equality CodeChef Solution in GO

``````package main

import (
"bufio"
"bytes"
"fmt"
"os"
"sort"
)

func main() {
reader := bufio.NewReader(os.Stdin)
tc := readNum(reader)
var buf bytes.Buffer
for tc > 0 {
tc--
n := readNum(reader)
A := readNNums(reader, n)
res := solve(n, A)
buf.WriteString(fmt.Sprintf("%d\n", res))
}
fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

func readNum(reader *bufio.Reader) (a int) {
bs, _ := reader.ReadBytes('\n')
readInt(bs, 0, &a)
return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
res := readNNums(reader, 2)
a, b = res[0], res[1]
return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
res := readNNums(reader, 3)
a, b, c = res[0], res[1], res[2]
return
}

func readNNums(reader *bufio.Reader, n int) []int {
res := make([]int, n)
x := 0
bs, _ := reader.ReadBytes('\n')
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
x = readInt(bs, x, &res[i])
}
return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func solve(n int, A []int) int {
sort.Ints(A)
// the best is to get A[0]
var cnt = 1
for i := 1; i < n; i++ {
if A[i] == A[0] {
cnt++
continue
}
// A[i] % m == A[0]
d := A[i] - A[0]
// d % m == 0
// d = x * m where x >= 1 and m > A[0]
if d <= A[0] {
// can't make A[i] to A[0], but to make them equal, need some value less than A[0], so we also need to change A[0] too
return n
}
}

return n - cnt
}``````
##### Mod Equality CodeChef Solution Review:

In our experience, we suggest you solve this Mod Equality CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Mod Equality CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Mod Equality CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

###### More Coding Solutions >>

Cognitive Class Answer