Problem Author: | Hasan Saleh (MathModel) |
Prepared by: | Hasan Saleh (MathModel) |
Edited by: | Hasan Saleh (MathModel) |
Solution
We can eliminate the mid term side , and only consider the leftmost and rightmost sides.
There is no case where x+y \ge x^y except for and where is integer.
We discount all pairs of , let the count of be then we discount \frac{f(2) \times (f(2)-1)}{2}.
We discount all pairs of (including 's) , so we remove :
pairs of which is \frac{f(1) \times (f(1)-1)}{2}
paris of which is f(1) \times (n-f(1)).
Then our Answer is ready !.
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*3
for i in a:
if(i<=2):cnt[i]+=1
ans=(n*(n-1))//2
ans-=(cnt[2]*(cnt[2]-1))//2
ans-=(cnt[1]*(cnt[1]-1))//2
ans-=(cnt[1])*(n-cnt[1])
print(ans)