exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | ca7fd5d92bc0679ef75701836a83dbb1 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Jumper {
public static void main(String[] args) {
handmadeInput.FastReader in = new handmadeInput.FastReader();
StringBuilder stringBuilder = new StringBuilder();
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
long[] qus = new long[n + 1];
for (int i = 1; i <= n; i++) {
qus[i] = in.nextInt();
}
long ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = (int) qus[i] - i; j <= n; j += qus[i]) {
if (j > i)
if ((qus[i] * qus[j] == i + j))
ans++;
}
}
stringBuilder.append(ans).append(" ");
}
System.out.println(stringBuilder);
}
}
// Additional Classes go here
class handmadeInput {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
class UtilityFunctions {
//! returns gcd of given numbers
public int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public int primeFactors(int n) {
HashMap<Integer, Integer> hashMap = new HashMap<>(n);
int c = 0;
// Print the number of 2s that divide n
while (n % 2 == 0) {
// if (hashMap.containsKey(2)) {
// hashMap.replace(2, hashMap.get(2) + 1);
// } else {
// hashMap.put(2, 1);
// }
c++;
n /= 2;
}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (int i = 3; i <= Math.sqrt(n); i += 2) {
// While i divides n, print i and divide n
while (n % i == 0) {
//System.out.print(i + " ");
// if (hashMap.containsKey(i)) {
// hashMap.replace(i, hashMap.get(i) + 1);
// } else {
// hashMap.put(i, 1);
// }
c++;
n /= i;
}
}
// This condition is to handle the case whien
// n is a prime number greater than 2
if (n > 2) {
// if (hashMap.containsKey(n)) {
// hashMap.replace(n, hashMap.get(n) + 1);
// } else {
// hashMap.put(n, 1);
// }
c++;
}
//System.out.print(n);
return c;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 7227d8b7ff45c6fe4c8fb9e7aef0a1c1 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class p4 {
public static void main(String[] args) throws IOException {
Scanner sc= new Scanner(System.in);
long t= sc.nextLong();
for(int k=0;k<t;k++) {
long n=sc.nextLong();
int ans=0;
long [] a=new long[(int)n];
for(int j=0;j<n;j++) {
a[j]=sc.nextLong();
}
for(int i=0;i<n;i++) {
int j=i+1;
while(j<n) {
if(a[i]*a[j]==i+j+2) {
ans++;
}
j+=a[i]-((i+j+2)%a[i]);
}
}
System.out.println(ans);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 825324687bf5466bde00ee63677356a9 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Collections;
import java.util.*;
public class Main {
public static void main(String args[] ) throws Exception
{
Solve instance = Solve.getInstance();
instance.test();
}
}
class Solve{
static FastReader sc;
static Solve instance = null;
long f[];
long table[][];
int k;
private Solve(){
sc = new FastReader();
}
public static Solve getInstance(){
if(instance == null)
instance = new Solve();
return instance;
}
private void input(){
}
public void test()
{
int t = sc.nextInt();
while(t>0)
{
int n = sc.nextInt();
int counter = 0;
Integer a[] = new Integer[n+1];
HashMap<Integer,Integer> map = new HashMap<>();
a[0] = 0;
for(int i = 1;i<=n;i++){
a[i] = sc.nextInt();
map.put(a[i],i);
}
Arrays.sort(a);
for(int i = 1;i<=n && a[i]*a[i] < 2*n ;i++)
{
//sout(a[i] +"\n");
for(int j = i+1;j<=n && a[j]*a[i] < 2*n;j++){
int indexI = map.get(a[i]);
int IndexJ = map.get(a[j]);
if((a[j]*a[i]) == (indexI+IndexJ))
counter++;
}
}
sout(counter+"\n");
t--;
}
}
public long re(long n,int m)
{
if(n == 0)
return 0 ;
if(n > 0 && m == 0)
return (power(n,k))%(1000000007);
else
{
if(table[(int)n][m] == 0)
table[(int)n][m] = (re(n-1,m) + re(n,m-1))%(1000000007);
}
return (table[(int)n][m])%(1000000007);
}
long power(long x, int y)
{
if (y == 0)
return 1;
else if (y % 2 == 0)
return power(x, y / 2) * power(x, y / 2);
else
return x * power(x, y / 2) * power(x, y / 2);
}
public void sout(Object s){
System.out.print(s);
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c3cc3e41764af034fdd8c75244704f99 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class PleasantPairs {
public static PrintWriter out;
private static final long MOD = 1000000007;
private static final double INFINITY = 1e18;
private static Scanner sc;
public static void main(String[] args) {
PleasantPairs ans = new PleasantPairs();
out = new PrintWriter(new BufferedOutputStream(System.out));
ans.solve();
out.close();
}
private void solve() {
sc =new Scanner(System.in);
int tests = sc.nextInt();
while(tests-->0) {
int N = sc.nextInt();
int []array = new int[N+1];
for(int i=1;i<=N;i++){
array[i] = sc.nextInt();
}
solve(array, N);
}
}
private void solve(int []array, int N) {
int result =0;
for(int i=1;i<=N;i++){
int product = (i/array[i]+1)*array[i];
int j = product-i;
//System.out.printf("product: %d j: %d\n", product, j);
while(j<=N) {
int v1 = array[i];
int v2 = array[j];
//System.out.printf("i: %d j: %d v1: %d v2: %d\n", i+1,j+1, v1, v2);
if((i!=j) && ((v1*v2) == (i+j))) result++;
product += array[i];
j = product-i;
}
}
out.println(result/2);
}
private int[] readIntArray(int N) {
int [] array = new int[N];
for(int i=0;i<N;i++){
array[i] = sc.nextInt();
}
return array;
}
private long[] readLongArray(int N) {
long [] array = new long[N];
for(int i=0;i<N;i++){
array[i] = sc.nextLong();
}
return array;
}
private long power(long a, long b) {
if(b==0) return 1L;
if(b==1) return a;
long result = power(a,b/2);
result*=result;
if (isOdd(b)) result *=b;
return result;
}
private boolean isOdd(long a){
return (a&1)==1;
}
private long[] convertToBinary(long N) {
int LOGN=0;
while((1L<<(LOGN))<=N) LOGN++;
long []array = new long[LOGN];
for(int i=LOGN-1;i>=0;i--){
array[i] = N&1;
N=N>>1;
}
return array;
}
private long[] copyToArrayFromBack(long[]to, long []from) {
int j = to.length-1;
for(int i=from.length-1;i>=0;i--) {
to[j--] = from[i];
}
return to;
}
private void printPrecision(double val, int precision) {
out.printf("%."+precision+"f\n",val);
}
private boolean isBitSet(int N, int i) {
return (N&(1<<i))>0;
}
private int setBit(int N, int i) {
return N|(1<<i);
}
private int clearBit(int N, int i) {
int mask = ~(1<<i);
return N&mask;
}
private int updateBit(int N, int pos, int value) {
clearBit(N, pos);
return N|(1<<value);
}
private int blowLastIBits(int N, int i) {
int mask = -1<<i;
return N&mask;
}
private Equation extendedGCD(long a, long b) {
if (a==0) return new Equation(b, 0, 1);
Equation e = extendedGCD(b%a, a);
return new Equation(e.gcd, e.y-((b/a)*e.x), e.x);
}
private long modularInverse(long a, long M) {
Equation e = extendedGCD(a, M);
return e.x%M;
}
private int blowBitsBetweenRange(int N, int i, int j) {
int a = -1<<(i+1);
int b = (1<<j)-1;
int mask = a|b;
return N&mask;
}
private long gcd(long a, long b) {
if(b==0) return a;
return gcd(b, a%b);
}
private long power(long a, long N, long MOD) {
long result = 1;
while(N>0) {
if((N&1)>0) {
result = (result*a)%MOD;
}
a=(a*a)%MOD;
N=N>>1;
}
return result;
}
private int countOfSetBits(int N) {
int result =0;
while(N>0) {
// blows of the last bit
N=N&(N-1);
result++;
}
return result;
}
private int closestLeft(long[] array, long target) {
int N = array.length;
int lo=0, hi=N-1;
if(array[0]>target) return 0;
if(array[hi]<target) return N;
int ans =0;
while(lo<=hi) {
int mid = lo+(hi-lo)/2;
if (array[mid]<=target) {
ans = mid;
lo= mid+1;
} else {
hi= mid-1;
}
}
return ans+1;
}
private int closestLeftInList(List<Long> array, long target) {
int N = array.size();
int lo=0, hi=N-1;
if(array.get(0)>target) return 0;
if(array.get(hi)<target) return N;
int ans =0;
while(lo<=hi) {
int mid = lo+(hi-lo)/2;
if (array.get(mid)<=target) {
ans = mid;
lo= mid+1;
} else {
hi= mid-1;
}
}
return ans+1;
}
private int closestRightInList(List<Long> array, long target) {
int N = array.size();
int lo=0, hi=N-1;
if(array.get(lo)>=target) return 1;
if(array.get(hi)<target) return N+1;
int ans=0;
while(lo<=hi) {
int mid = lo+ (hi-lo)/2;
if(array.get(mid)>=target) {
ans=mid;
hi=mid-1;
} else {
lo=mid+1;
}
}
return ans+1;
}
private int closestRight(long[] array, long target) {
int N = array.length;
int lo=0, hi=N-1;
if(array[lo]>=target) return 1;
if(array[hi]<target) return N+1;
int ans=0;
while(lo<=hi) {
int mid = lo+ (hi-lo)/2;
if(array[mid]>=target) {
ans=mid;
hi=mid-1;
} else {
lo=mid+1;
}
}
return ans+1;
}
}
class Equation {
long gcd,x,y;
public Equation(long gcd, long x, long y) {
this.gcd = gcd;
this.x = x;
this.y = y;
}
}
class Point {
int x,y;
public Point(int x, int y){
this.x = x;
this.y = y;
}
public double distanceFrom(Point p) {
return (p.x-x)*(p.x-x)*1.0 + (p.y-y)*(p.y-y)*1.0;
}
public int intDistFrom(Point p) {
return (p.x-x)*(p.x-x) + (p.y-y)*(p.y-y);
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c58af285f2770ffc6b475dc167e4a96d | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package MyPackage;
import java.io.*;
import java.util.*;
public class MyClass {
final static long mod = 1_000_000_007;
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long value : a) {
l.add(value);
}
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int value : a) {
l.add(value);
}
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String n() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nint() {
return Integer.parseInt(n());
}
long nlong() {
return Long.parseLong(n());
}
double ndouble() {
return Double.parseDouble(n());
}
String nline() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nint();
while(t-- > 0) {
int n = sc.nint();
int[] arr = new int[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = sc.nint();
}
out.println(solution(arr, n));
}
out.flush();
out.close();
}
public static int solution(int[] arr, int n) {
int count = 0;
for(int i = 1; i <= n; i++) {
int temp = (i / arr[i] + 1) * arr[i];
while(temp - i <= n) {
if(i != temp - i && arr[temp - i] == temp / arr[i]) {
count++;
}
temp += arr[i];
}
}
return count / 2;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | be25cd2a2b3a5eae416c1f4bb52562bc | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package MyPackage;
import java.io.*;
import java.util.*;
public class MyClass {
final static long mod = 1_000_000_007;
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long value : a) {
l.add(value);
}
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int value : a) {
l.add(value);
}
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String n() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nint() {
return Integer.parseInt(n());
}
long nlong() {
return Long.parseLong(n());
}
double ndouble() {
return Double.parseDouble(n());
}
String nline() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nint();
while(t-- > 0) {
int n = sc.nint();
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = sc.nint();
}
out.println(solution(arr, n));
}
out.flush();
out.close();
}
public static int solution(int[] arr, int n) {
int count = 0;
HashMap<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < n; i++) {
map.put(arr[i], i + 1);
}
sort(arr);
for (int i = 0; i < n && arr[i] * arr[i] <= 2 * n; i++) {
for (int j = i + 1; j < n && arr[i] * arr[j] <= 2 * n; j++) {
if (arr[i] * arr[j] == map.get(arr[i]) + map.get(arr[j]))
count++;
}
}
return count;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 4f13066f4c16890314b5d50864c145b6 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package MyPackage;
import java.io.*;
import java.util.*;
public class MyClass {
final static long mod = 1_000_000_007;
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long value : a) {
l.add(value);
}
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int value : a) {
l.add(value);
}
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String n() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nint() {
return Integer.parseInt(n());
}
long nlong() {
return Long.parseLong(n());
}
double ndouble() {
return Double.parseDouble(n());
}
String nline() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nint();
while(t-- > 0) {
int n = sc.nint();
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = sc.nint();
}
out.println(solution(arr, n));
}
out.flush();
out.close();
}
public static int solution(int[] arr, int n) {
int count = 0;
HashMap<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < n; i++) {
map.put(arr[i], i + 1);
}
sort(arr);
for(int i = 1; i < n; i++) {
if(arr[0] * arr[i] == map.get(arr[0]) + map.get(arr[i])) {
count++;
}
}
for(int i = 1; i < n; i++) {
for(int j = i + 1; j < 2 * n / (i + 1); j++) {
if(arr[i] * arr[j] == map.get(arr[i]) + map.get(arr[j])) {
count++;
}
}
}
return count;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | e6f8ff1b542bb5f3a50cbe076ab91a80 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static class Pair {
int key, value;
public Pair(int key, int value) {
this.key = key;
this.value = value;
}
}
static class Node {
long index, value;
public Node(long index, long value) {
this.value = value;
this.index = index;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
//BINARY EXPONENTIATION
public static long binpow(long a, long b) {
long res = 1;
while (b > 0) {
if ((b & 1) == 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
// Returns factorial of n
static long fact(long n) {
if (n == 0)
return 1;
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
public static void main(String[] args)
{
FastReader s = new FastReader();
int t = s.nextInt();
//int t = 1;
while (t-- > 0) {
int n = s.nextInt();
Node[] a = new Node[n];
for (int i = 0; i < n; i++) {
a[i] = new Node(i + 1, s.nextInt());
}
Arrays.sort(a, Comparator.comparingLong(o -> o.value));
long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
long now = a[i].value * a[j].value;
if (now == a[i].index + a[j].index) {
ans++;
}
if (now > 2L * n) {
break;
}
}
}
System.out.println(ans);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | e4722c7844602e05e263a99112cbafe7 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long[] ar;
int n = 0;
int count = 0;
int t = scan.nextInt();
while(t-->0){
n = scan.nextInt();
ar = new long[n+1];
for(int i=1;i<=n;i++){
ar[i] = scan.nextLong();
}
for(int i=1;i<n;i++){
int x = (int)ar[i] - i;
for(int j= x;j<=n;j+=ar[i]){
if(i<j){
if((long)(ar[i]*ar[j])==i+j) ++count;
}
}
}
System.out.println(count);
count = 0;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 12a4e950455c54cbe389455a1589cd72 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class GFG {
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc=new FastReader();
int n=sc.nextInt();
for(int g=0;g<n;g++){
int size =sc.nextInt();
int count =0;
int arr[]=new int[size+1];
for(int i=1;i<=size;i++){
arr[i]= sc.nextInt();
}
for(int i=1;i<size;i++){
for(int j=arr[i]-i;j<=size;j+=arr[i]){
if(j>i&&((long)arr[i]*arr[j]==(i+j))){
count++;
}
}
}System.out.println(count);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | a51337ea7def7ec83910437a50c18cbc | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
/*package whatever //do not write package name here */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class GFG {
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) {
FastReader sc=new FastReader();
int n=sc.nextInt();
for(int g=0;g<n;g++){
int size =sc.nextInt();
int count =0;
int arr[]=new int[size+1];
for(int i=1;i<=size;i++){
arr[i]= sc.nextInt();
}
for(int i=1;i<size;i++){
for(int j=arr[i]-i;j<=size;j+=arr[i]){
if(j>=1)
if(((long)arr[i]*arr[j]==i+j)&&(i<j))
count++;
}
}System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 28a5f879349df37cdf818561924000f2 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Codeforces1 {
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter o = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while(t-->0)
{
String st[] = br.readLine().trim().split(" ");
int n =Integer.parseInt(st[0]);
long a[] = new long[n+1];
String st1[] = br.readLine().trim().split(" ");
for(int i=0;i<n;i++) a[i+1] = Long.parseLong(st1[i]);
long count=0;
for(int i=1;i<=n;i++)
{
long temp = (i/a[i] +1)*a[i];
for( long j=temp-i;j<=n;j=j+a[i])
{
if(j>i&&temp!=i&&a[(int)j]==(j+i)/a[i])
count++;
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 317044f24fdf9579fdef0d7e9d4159d3 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
StringTokenizer st
= new StringTokenizer(br.readLine());
int i,j,n,t,p;
long k,l,x;
t = Integer.parseInt(st.nextToken());
for(p=1;p<=t;p++)
{
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
long a[] = new long[n];
st = new StringTokenizer(br.readLine());
HashMap<Long,Long> m = new HashMap<Long,Long>();
for(i=0;i<n;i++)
{
a[i] = Long.parseLong(st.nextToken());
m.put(a[i],(long)(i+1));
}
Arrays.sort(a);
l = 0;
for(i=0;i<n-1;i++)
{ k = m.get(a[i]);
for(j=i+1;j<n;j++)
{
x = m.get(a[j]);
if(a[i]*a[j] == x+k)
{
l++;
}
if(a[i]*a[j]>2*n)
break;
}
}
System.out.println(l);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 883a10a7b12aadef4884aee0ed07188d | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Stack3 {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
static Reader sc = new Reader();
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
//subsequence("abcdefghij");
/*
* For integer input: int n=inputInt();
* For long input: long n=inputLong();
* For double input: double n=inputDouble();
* For String input: String s=inputString();
* Logic goes here
* For printing without space: print(a+""); where a is a variable of any datatype
* For printing with space: printSp(a+""); where a is a variable of any datatype
* For printing with new line: println(a+""); where a is a variable of any datatype
*/
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
boolean[] ar = new boolean[2 * n + 1];
int[] index=new int[2*n+1];
for (int j = 0; j < n; j++) {
int num = sc.nextInt();
ar[num] = true;
index[num]=j+1;
}
long ans = 0;
for (int k = 3; k <= 2 * n - 1; k++) {
for (int p = 1; p * p <= k; p++) {
if (k % p == 0) {
if (k / p != p && ar[k / p] && ar[p] ) {
//System.out.println(k+" "+p+" "+k/p);
double an1=(index[p]+index[k/p])/(double)k;
if(an1==1)
ans++;
}
}
}
}
System.out.println(ans);
}
bw.flush();
bw.close();
}
public static boolean checkPrime(int n) {
if (n == 0 || n == 1) {
return false;
}
for (int j = 2; j * j <= n; j++) {
if (n % j == 0) {
return false;
}
}
return true;
}
public static void dfs1(List<List<Integer>> g, boolean[] visited, Stack<Integer> stack, int num) {
visited[num] = true;
for (Integer integer : g.get(num)) {
if (!visited[integer]) {
dfs1(g, visited, stack, integer);
}
}
stack.push(num);
}
public static void dfs2(List<List<Integer>> g, boolean[] visited, List<Integer> list, int num, int c,
int[] raj) {
visited[num] = true;
for (Integer integer : g.get(num)) {
if (!visited[integer]) {
dfs2(g, visited, list, integer, c, raj);
}
}
raj[num] = c;
list.add(num);
}
public static int inputInt() throws IOException {
return sc.nextInt();
}
public static long inputLong() throws IOException {
return sc.nextLong();
}
public static double inputDouble() throws IOException {
return sc.nextDouble();
}
public static String inputString() throws IOException {
return sc.readLine();
}
public static void print(String a) throws IOException {
bw.write(a);
}
public static void printSp(String a) throws IOException {
bw.write(a + " ");
}
public static void println(String a) throws IOException {
bw.write(a + "\n");
}
public static long getAns(int[] ar, int c, long[][] dp, int i, int sign) {
if (i < 0) {
return 1;
}
if (c <= 0) {
return 1;
}
dp[i][c] = Math.max(dp[i][c], Math.max(ar[i] * getAns(ar, c - 1, dp, i - 1, sign), getAns(ar, c, dp, i - 1, 1)));
return dp[i][c];
}
public static long power(long a, long b, long c) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = ans * a;
ans %= c;
}
a = a * a;
a %= c;
b /= 2;
}
return ans;
}
public static long power1(long a, long b, long c) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = multiply(ans, a, c);
}
a = multiply(a, a, c);
b /= 2;
}
return ans;
}
public static long multiply(long a, long b, long c) {
long res = 0;
a %= c;
while (b > 0) {
if (b % 2 == 1) {
res = (res + a) % c;
}
a = (a + a) % c;
b /= 2;
}
return res % c;
}
public static long totient(long n) {
long result = n;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
//sum=sum+2*i;
while (n % i == 0) {
n /= i;
// sum=sum+n;
}
result -= result / i;
}
}
if (n > 1) {
result -= result / n;
}
return result;
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public int sumOfFlooredPairs(int[] nums) {
// long sum=0;
long mod = (long) (1e9 + 7);
Arrays.sort(nums);
long[] numerator = new long[nums.length];
long[] denominator = new long[nums.length];
long[] numerator1 = new long[nums.length];
long[] denominator1 = new long[nums.length];
long num = 1;
long den = nums[0];
numerator[0] = 1;
denominator[0] = den;
long num1 = 1;
long den1 = nums[nums.length - 1];
numerator1[nums.length - 1] = 1;
denominator1[nums.length - 1] = den1;
for (int i = 1; i < nums.length; i++) {
long gcd1 = gcd(denominator[i - 1], nums[i]);
long lcm = (denominator[i - 1] * nums[i]) / gcd1;
long n1 = lcm / denominator[i - 1] * numerator[i - 1] + lcm / nums[i];
numerator[i] = n1;
denominator[i] = lcm;
long gcd2 = gcd(denominator1[nums.length - i], nums[nums.length - 1 - i]);
long lcm1 = (denominator1[nums.length - i] * nums[nums.length - 1 - i]) / gcd2;
long n2 = lcm1 / denominator1[nums.length - i] * numerator1[nums.length - i] + lcm1 / nums[nums.length - 1 - i];
numerator1[nums.length - 1 - i] = n2;
denominator1[nums.length - 1 - i] = lcm1;
/* prefix[i]=sum;
sum12+=1d/nums[nums.length-1-i];
prefix2[nums.length-1-i]=sum12;*/
}
/*System.out.println(Arrays.toString(numerator));
System.out.println(Arrays.toString(denominator));*/
int sum2 = 0;
for (int i = 0; i < nums.length; i++) {
//float d1=(float)(numerator[i]/(double)denominator[i]);
sum2 += (int) (Math.floor((numerator[i] * nums[i]) / (double) denominator[i]));
sum2 %= mod;
if (i + 1 < nums.length) {
// float d2=(float)(numerator1[i+1]/(double)denominator1[i+1]);
sum2 += (int) (Math.floor((numerator1[i + 1] * nums[i]) / (double) denominator1[i + 1]));
sum2 %= mod;
}
}
return sum2;
}
public static boolean[] primes(int n) {
boolean[] p = new boolean[n + 1];
p[0] = false;
p[1] = false;
for (int i = 2; i <= n; i++) {
p[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (p[i]) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
public String LargestEven(String S) {
// char[] ar=S.toCharArray();
int[] count = new int[10];
for (int i = 0; i < S.length(); i++) {
count[S.charAt(i) - '0']++;
}
int num = -1;
for (int i = 0; i <= 8; i += 2) {
if (count[i] > 0) {
num = i;
break;
}
}
StringBuilder ans = new StringBuilder();
for (int i = 9; i >= 0; i--) {
if (i != num) {
for (int j = 1; j <= count[i]; j++) {
ans.append(i);
}
} else {
for (int j = 1; j <= count[num] - 1; j++) {
ans.append(num);
}
}
}
if (num != -1 && count[num] > 0) {
ans.append(num);
}
return ans.toString();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 555a40ceca87ea94e7e3c5930b1dcd02 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.math.BigInteger;
//import javafx.util.*;
public final class B
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
static long mod=(long)(1e9+7);
static int D1[],D2[],par[];
static boolean set[];
static int value[];
static long INF=Long.MAX_VALUE;
static int val[],tot[],max[];
static int min;
static int dp[][];
static int path[][],A[];
static char X[][];
static int index[];
public static void main(String args[])throws IOException
{
int T=i();
outer:while(T-->0)
{
int N=i();
int A[]=new int[N];
int f[]=new int[2*N+5];
for(int i=0; i<N; i++)
{
A[i]=i();
f[A[i]]=i+1;
}
int c=0;
for(int i=3; i<=2*N; i++)
{
for(int j=1; j<Math.sqrt(i); j++)
{
if(i%j==0)
{
int a=f[j],b=f[i/j];
if(a!=0 && b!=0 && j*j!=i)
{
if(a+b==i)c++;
}
}
}
}
out.println(c);
}
out.close();
}
static int or(int i,int j)
{
System.out.println("OR "+i+" ");
return i();
}
static int and(int i,int j)
{
System.out.println("AND "+i+" "+j);
return i();
}
static int xor(int i,int j)
{
System.out.println("XOR "+i+" "+j);
return i();
}
static String f(char X[],int d,int K)
{
StringBuilder sb=new StringBuilder();
StringBuilder s=new StringBuilder();
int x=K/d;
String Y="";
for(int i=0; i<d; i++)s.append(X[i]);
Y=s.toString();
while(x-->0)
sb.append(Y);
x=K%d;
for(int i=0; i<x; i++)sb.append(X[i]);
return sb.toString();
}
static long f(long t,long x,long N,long v)
{
long l=0,r=N+1;
while(r-l>1)
{
long m=(l+r)/2;
if(t+m*x<=N*x)l=m;
else r=m;
}
return l;
}
static void f(int dp[][],int d,int A[],int par[])
{
if(A[d]==0)return ;
f(dp,d+1,A,par);
dp[0][d]=A[d]+Math.min(dp[0][d+1], dp[1][d+1]);
if(dp[0][d+1]<dp[1][d+1])
{
par[d]=1;
}
else par[d]=2;
dp[1][d]=dp[0][d+1];
}
static int [] ask(int a,int N)
{
System.out.println("? "+a);
int A[]=input(N);
return A;
}
static boolean isPalin(char X[])
{
int l=0,r=X.length-1;
while(l<=r)
{
if(X[l]!=X[r])return false;
l++;
r--;
}
return true;
}
static boolean isSorted(int A[])
{
int N=A.length;
for(int i=0; i<N-1; i++)
{
if(A[i]>A[i+1])return false;
}
return true;
}
static int f1(int x,ArrayList<Integer> A)
{
int l=-1,r=A.size();
while(r-l>1)
{
int m=(l+r)/2;
int a=A.get(m);
if(a<x)l=m;
else r=m;
}
return l;
}
static int max(int a,int b,int c)
{
return Math.max(a, Math.max(c, b));
}
static int value(char X[],char Y[])
{
int c=0;
for(int i=0; i<7; i++)
{
if(Y[i]=='1' && X[i]=='0')return -1;
if(X[i]=='1' && Y[i]=='0')c++;
}
return c;
}
// static boolean isValid(int i,int j)
// {
// if(i<0 || i>=N)return false;
// if(j<0 || j>=M)return false;
// return true;
// }
static long fact(long N)
{
long num=1L;
while(N>=1)
{
num=((num%mod)*(N%mod))%mod;
N--;
}
return num;
}
static boolean reverse(long A[],int l,int r)
{
while(l<r)
{
long t=A[l];
A[l]=A[r];
A[r]=t;
l++;
r--;
}
if(isSorted(A))return true;
else return false;
}
static boolean isSorted(long A[])
{
for(int i=1; i<A.length; i++)if(A[i]<A[i-1])return false;
return true;
}
static boolean isPalindrome(char X[],int l,int r)
{
while(l<r)
{
if(X[l]!=X[r])return false;
l++; r--;
}
return true;
}
static long min(long a,long b,long c)
{
return Math.min(a, Math.min(c, b));
}
static void print(int a)
{
System.out.println("! "+a);
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
a=find(a);
b=find(b);
if(a!=b)
{
par[a]+=par[b]; //transfers the size
par[b]=a; //changes the parent
}
}
static void swap(char A[],int a,int b)
{
char ch=A[a];
A[a]=A[b];
A[b]=ch;
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void setGraph(int N)
{
g=new ArrayList[N+1];
val=new int[N+1];
for(int i=0; i<=N; i++)
{
g[i]=new ArrayList<Integer>();
}
}
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 void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
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 GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
//Debugging Functions Starts
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
//Debugging Functions END
//----------------------
//IO FUNCTIONS STARTS
static HashMap<Integer,Integer> Hash(int A[])
{
HashMap<Integer,Integer> mp=new HashMap<>();
for(int a:A)
{
int f=mp.getOrDefault(a,0)+1;
mp.put(a, f);
}
return mp;
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
//IO FUNCTIONS END
}
class node implements Comparable<node>
{
int par,a;
node(int par,int a)
{
this.par=par;
this.a=a;
}
public int compareTo(node x)
{
return this.par-x.par;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
//gey
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 91ac287e2fc62d8d9dff67d466519667 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | // 1 2 3 are easy , think of a pattern that you think can't be the answer
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws IOException{
if (System.getProperty("ONLINE_JUDGE") == null) {
PrintStream ps = new PrintStream(new File("output.txt"));
InputStream is = new FileInputStream("input.txt");
System.setIn(is);
System.setOut(ps);
}
Scanner scn = new Scanner(System.in);
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int ntc = in.nextInt();
// int ntc = 1;
while(ntc-- > 0){
solve(in , out , scn);
}
out.flush();
}
public static void solve(FastReader in , PrintWriter out , Scanner scn){
int n = in.nextInt();
Pair[] arr = new Pair[n];
for (int i = 0; i < n; i++) {
int curr = in.nextInt();
arr[i] = new Pair(curr, i + 1);
}
Arrays.sort(arr, (a, b) -> a.first - b.first);
long ans = 0;
int curr = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if ((arr[j].first) > (2 * n) / arr[i].first) {
break;
}
if ((arr[i].first * arr[j].first) == arr[i].second + arr[j].second) {
ans++;
}
}
}
out.println(ans);
}
/*
*** *** ***
*/
public static boolean check(StringBuilder sb , int one){
HashMap<Character, Integer> map = new HashMap<>();
int cc = 0;
int flag = 0;
for(int i = sb.length()-1 ; i >= 0 ; i--){
if(sb.charAt(i) == '1') cc++;
else flag = 1;
if(flag == 0 && cc == one) return true;
}
return false;
}
static class Pair{
int first;
int second;
Pair( int first , int second){
this.first =first;
this.second = second;
}
}
static int gcd(int a, int b) {
while (b != 0) {
int t = a;
a = b;
b = t % b;
}
return a;
} public static boolean isPrime(int 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;
}
public static void println(long n){System.out.println(n);}
public static void print(long n){System.out.print(n);}
public static void print(int n ){System.out.print(n);}
public static void println(int n){System.out.println(n);}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | bdd173c161c3fa515344833512763df9 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | // 1 2 3 are easy , think of a pattern that you think can't be the answer
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws IOException{
if (System.getProperty("ONLINE_JUDGE") == null) {
PrintStream ps = new PrintStream(new File("output.txt"));
InputStream is = new FileInputStream("input.txt");
System.setIn(is);
System.setOut(ps);
}
Scanner scn = new Scanner(System.in);
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int ntc = in.nextInt();
// int ntc = 1;
while(ntc-- > 0){
solve(in , out , scn);
}
out.flush();
}
public static void solve(FastReader in , PrintWriter out , Scanner scn){
int n = in.nextInt();
Pair[] arr = new Pair[n];
for (int i = 0; i < n; i++) {
int curr = in.nextInt();
arr[i] = new Pair(curr, i + 1);
}
Arrays.sort(arr, (a, b) -> a.first - b.first);
long ans = 0;
int curr = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if ((arr[j].first) > (2 * n) / (i + 1)) {
break;
}
if ((arr[i].first * arr[j].first) == arr[i].second + arr[j].second) {
ans++;
}
}
}
out.println(ans);
}
/*
*** *** ***
*/
public static boolean check(StringBuilder sb , int one){
HashMap<Character, Integer> map = new HashMap<>();
int cc = 0;
int flag = 0;
for(int i = sb.length()-1 ; i >= 0 ; i--){
if(sb.charAt(i) == '1') cc++;
else flag = 1;
if(flag == 0 && cc == one) return true;
}
return false;
}
static class Pair{
int first;
int second;
Pair( int first , int second){
this.first =first;
this.second = second;
}
}
static int gcd(int a, int b) {
while (b != 0) {
int t = a;
a = b;
b = t % b;
}
return a;
} public static boolean isPrime(int 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;
}
public static void println(long n){System.out.println(n);}
public static void print(long n){System.out.print(n);}
public static void print(int n ){System.out.print(n);}
public static void println(int n){System.out.println(n);}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 5f9bb33cf032a0c71247e7fb21f64733 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
//import javafx.util.*;
public class Main
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
//static ArrayList<ArrayList<TASK>> t;
static long mod=(long)(1e9+7);
static boolean set[],post[][];
static int prime[],c[];
static int par[];
// static int dp[][];
static HashMap<String,Long> mp;
static long max=1;
static boolean temp[][];
static int K=0;
static int size[],dp[][],iv_A[],iv_B[];
static long modulo = 998244353;
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
int t = i();
while(t-- > 0){
int n = i();
int[] arr = new int[n+1];
for(int i = 1;i < n + 1;i++){
arr[i] = i();
}
long count = 0;
for(int i = 1;i < n;i++){
for(int j = arr[i] - i;j <= n;j += arr[i]){
if(j >= 1){
if(((long)arr[i]*arr[j]==i+j)&&(i<j)){
count++;
}
}
}
}
System.out.println(count);
}
}
static Boolean isSubsetSum(int n, int arr[], int sum){
// code here
boolean[][] dp = new boolean[n+1][sum+1];
for(int i = 0;i < n+1;i++){
for(int j = 0;j < sum + 1;j++){
if(i == 0){
dp[i][j] = false;
}
if(j == 0){
dp[i][j] = true;
}
}
}
for(int i = 1;i < n+1;i++){
for(int j = 1;j < sum + 1;j++){
if(arr[i-1] <= j){
dp[i][j] = dp[i-1][j - arr[i-1]] || dp[i-1][j];
}else{
dp[i][j] = dp[i-1][j];
}
}
}
return dp[n][sum];
}
static int getmax(ArrayList<Integer> arr){
int n = arr.size();
int max = Integer.MIN_VALUE;
for(int i = 0;i < n;i++){
max = Math.max(max,arr.get(i));
}
return max;
}
static boolean check(ArrayList<Integer> arr){
int n = arr.size();
boolean flag = true;
for(int i = 0;i < n-1;i++){
if(arr.get(i) != arr.get(i+1)){
flag = false;
break;
}
}
return flag;
}
static int MinimumFlips(String s, int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = (s.charAt(i) == '1' ? 1 : 0);
}
// Initialize prefix arrays to store
// number of changes required to put
// 1s at either even or odd position
int[] oddone = new int[n + 1];
int[] evenone = new int[n + 1];
oddone[0] = 0;
evenone[0] = 0;
for (int i = 0; i < n; i++) {
// If i is odd
if (i % 2 != 0) {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 1 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 0 ? 1 : 0);
}
// Else i is even
else {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 0 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 1 ? 1 : 0);
}
}
// Initialize minimum flips
return Math.min(evenone[n],oddone[n]);
}
static int nextPowerOf2(int n)
{
int count = 0;
// First n in the below
// condition is for the
// case where n is 0
if (n > 0 && (n & (n - 1)) == 0){
while(n != 1)
{
n >>= 1;
count += 1;
}
return count;
}else{
while(n != 0)
{
n >>= 1;
count += 1;
}
return count;
}
}
static int length(int n){
int count = 0;
while(n > 0){
n = n/10;
count++;
}
return count;
}
static boolean isPrimeInt(int 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;
}
public static int lcs(int[] nums) {
int[] tails = new int[nums.length];
int size = 0;
for (int x : nums) {
int i = 0, j = size;
while (i != j) {
int m = (i + j) / 2;
if (tails[m] <= x)
i = m + 1;
else
j = m;
}
tails[i] = x;
if (i == size) ++size;
}
return size;
}
static int CeilIndex(int A[], int l, int r, int key)
{
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key)
r = m;
else
l = m;
}
return r;
}
static int f(int A[], int size)
{
// Add boundary case, when array size is one
int[] tailTable = new int[size];
int len; // always points empty slot
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0])
// new smallest value
tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1])
// A[i] wants to extend largest subsequence
tailTable[len++] = A[i];
else
// A[i] wants to be current end candidate of an existing
// subsequence. It will replace ceil value in tailTable
tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}
static int containsBoth(char X[],int N)
{
for(int i=1; i<N; i++)if(X[i]!=X[i-1])return i-1;
return -1;
}
static void f(char X[],int N,int A[])
{
int c=0;
for(int i=N-1; i>=0; i--)
{
if(X[i]=='1')
{
A[i]=c;
}
else c++;
A[i]+=A[i+1];
}
}
static int f(int i,int j,char X[],char Y[],int zero)
{
if(i==X.length && j==Y.length)return 0;
if(i==X.length)return iv_B[j]; //return inversion count here
if(j==Y.length)return iv_A[i];
if(dp[i][j]==-1)
{
int cost_x=0,cost_y=0;
if(X[i]=='1')
{
cost_x=zero+f(i+1,j,X,Y,zero);
}
else cost_x=f(i+1,j,X,Y,zero-1);
if(Y[j]=='1')
{
cost_y=zero+f(i,j+1,X,Y,zero);
}
else cost_y=f(i,j+1,X,Y,zero-1);
dp[i][j]=Math.min(cost_x, cost_y);
}
return dp[i][j];
}
static boolean f(long last,long next,long l,long r,long A,long B)
{
while(l<=r)
{
long m=(l+r)/2;
long s=((m)*(m-1))/2;
long l1=(A*m)+s,r1=(m*B)-s;
if(Math.min(next, r1)<Math.max(last, l1))
{
if(l1>last)r=m-1;
else l=m+1;
}
else return true;
}
return false;
}
static boolean isVowel(char x)
{
if(x=='a' || x=='e' || x=='i' ||x=='u' || x=='o')return true;
return false;
}
static boolean f(int i,int j)
{
//i is no of one
//j is no of ai>1
if(i==0 && j==0)return true; //this player has no pile to pick --> last move iska rha hoga
if(dp[i][j]==-1)
{
boolean f=false;
if(i>0)
{
if(!f(i-1,j))f=true;
}
if(j>0)
{
if(!f(i,j-1) && !f(i+1,j-1))f=true;
}
if(f)dp[i][j]=1;
else dp[i][j]=0;
}
return dp[i][j]==1;
}
static int last=-1;
static void dfs(int n,int p)
{
last=n;
System.out.println("n--> "+n+" p--> "+p);
for(int c:g[n])
{
if(c!=p)dfs(c,n);
}
}
static long abs(long a,long b)
{
return Math.abs(a-b);
}
static int lower(long A[],long x)
{
int l=0,r=A.length;
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<=x)l=m;
else r=m;
}
return l;
}
static int f(int i,int s,int j,int N,int A[],HashMap<Integer,Integer> mp)
{
if(i==N)
{
return s;
}
if(dp[i][j]==-1)
{
if(mp.containsKey(A[i]))
{
int f=mp.get(A[i]);
int c=0;
if(f==1)c++;
mp.put(A[i], f+1);
HashMap<Integer,Integer> temp=new HashMap<>();
temp.put(A[i],1);
return dp[i][j]=Math.min(f(i+1,s+1+c,j,N,A,mp), s+K+f(i+1,0,i,N,A,temp));
}
else
{
mp.put(A[i],1);
return dp[i][j]=f(i+1,s,j,N,A,mp);
}
}
return dp[i][j];
}
static boolean inRange(int a,int l,int r)
{
if(l<=a && r>=a)return true;
return false;
}
static long f(long a,long b)
{
if(a%b==0)return a/b;
else return (a/b)+f(b,a%b);
}
static void f(int index,long A[],int i,long xor)
{
if(index+1==A.length)
{
if(valid(xor^A[index],i))
{
xor=xor^A[index];
max=Math.max(max, i);
}
return;
}
if(dp[index][i]==0)
{
dp[index][i]=1;
if(valid(xor^A[index],i))
{
f(index+1,A,i+1,0);
f(index+1,A,i,xor^A[index]);
}
else
{
f(index+1,A,i,xor^A[index]);
}
}
}
static boolean valid(long xor,int i)
{
if(xor==0)return true;
while(xor%2==0 )
{
xor/=2;
i--;
}
return i<=0;
}
static int next(int i,long pre[],long S)
{
int l=i,r=pre.length;
while(r-l>1)
{
int m=(l+r)/2;
if(pre[m]-pre[i-1]>S)r=m;
else l=m;
}
return r;
}
static boolean lexo(long A[],long B[])
{
for(int i=0; i<A.length; i++)
{
if(B[i]>A[i])return true;
if(A[i]>B[i])return false;
}
return false;
}
static long [] f(long A[],long B[],int j)
{
int N=A.length;
long X[]=new long[N];
for(int i=0; i<N; i++)
{
X[i]=(B[j]+A[i])%N;
j++;
j%=N;
}
return X;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
b=find(b);
a=find(a);
if(a!=b)
{
par[b]=a;
}
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static long lower_Bound(long A[],int low,int high, long x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void setGraph(int N)
{
size=new int[N+1];
// D=new int[N+1];
g=new ArrayList[N+1];
for(int i=0; i<=N; i++)
{
g[i]=new ArrayList<>();
}
}
static long pow(long a,long b)
{
long pow=1L;
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(int 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 void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
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 GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | a36f923a5659b7adeae5b7628f56e7b9 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
//import javafx.util.*;
public class Main
{
static PrintWriter out = new PrintWriter(System.out);
static StringBuilder ans=new StringBuilder();
static FastReader in=new FastReader();
static ArrayList<Integer> g[];
//static ArrayList<ArrayList<TASK>> t;
static long mod=(long)(1e9+7);
static boolean set[],post[][];
static int prime[],c[];
static int par[];
// static int dp[][];
static HashMap<String,Long> mp;
static long max=1;
static boolean temp[][];
static int K=0;
static int size[],dp[][],iv_A[],iv_B[];
static long modulo = 998244353;
public static void main(String args[])throws IOException
{
/*
* star,rope,TPST
* BS,LST,MS,MQ
*/
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T-->0) {
int n=sc.nextInt();
int a[]=new int[n+1];
for(int i=1;i<=n;i++) {
a[i]=sc.nextInt();
}
long c=0;
for(int i=1;i<n;i++) {
for(int j=a[i]-i;j<=n;j+=a[i]) {
if(j>=1)
if(((long)a[i]*a[j]==i+j)&&(i<j))
c++;
}
}
System.out.println(c);
}
}
static Boolean isSubsetSum(int n, int arr[], int sum){
// code here
boolean[][] dp = new boolean[n+1][sum+1];
for(int i = 0;i < n+1;i++){
for(int j = 0;j < sum + 1;j++){
if(i == 0){
dp[i][j] = false;
}
if(j == 0){
dp[i][j] = true;
}
}
}
for(int i = 1;i < n+1;i++){
for(int j = 1;j < sum + 1;j++){
if(arr[i-1] <= j){
dp[i][j] = dp[i-1][j - arr[i-1]] || dp[i-1][j];
}else{
dp[i][j] = dp[i-1][j];
}
}
}
return dp[n][sum];
}
static int getmax(ArrayList<Integer> arr){
int n = arr.size();
int max = Integer.MIN_VALUE;
for(int i = 0;i < n;i++){
max = Math.max(max,arr.get(i));
}
return max;
}
static boolean check(ArrayList<Integer> arr){
int n = arr.size();
boolean flag = true;
for(int i = 0;i < n-1;i++){
if(arr.get(i) != arr.get(i+1)){
flag = false;
break;
}
}
return flag;
}
static int MinimumFlips(String s, int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = (s.charAt(i) == '1' ? 1 : 0);
}
// Initialize prefix arrays to store
// number of changes required to put
// 1s at either even or odd position
int[] oddone = new int[n + 1];
int[] evenone = new int[n + 1];
oddone[0] = 0;
evenone[0] = 0;
for (int i = 0; i < n; i++) {
// If i is odd
if (i % 2 != 0) {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 1 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 0 ? 1 : 0);
}
// Else i is even
else {
// Update the oddone
// and evenone count
oddone[i + 1]
= oddone[i]
+ (a[i] == 0 ? 1 : 0);
evenone[i + 1]
= evenone[i]
+ (a[i] == 1 ? 1 : 0);
}
}
// Initialize minimum flips
return Math.min(evenone[n],oddone[n]);
}
static int nextPowerOf2(int n)
{
int count = 0;
// First n in the below
// condition is for the
// case where n is 0
if (n > 0 && (n & (n - 1)) == 0){
while(n != 1)
{
n >>= 1;
count += 1;
}
return count;
}else{
while(n != 0)
{
n >>= 1;
count += 1;
}
return count;
}
}
static int length(int n){
int count = 0;
while(n > 0){
n = n/10;
count++;
}
return count;
}
static boolean isPrimeInt(int 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;
}
public static int lcs(int[] nums) {
int[] tails = new int[nums.length];
int size = 0;
for (int x : nums) {
int i = 0, j = size;
while (i != j) {
int m = (i + j) / 2;
if (tails[m] <= x)
i = m + 1;
else
j = m;
}
tails[i] = x;
if (i == size) ++size;
}
return size;
}
static int CeilIndex(int A[], int l, int r, int key)
{
while (r - l > 1) {
int m = l + (r - l) / 2;
if (A[m] >= key)
r = m;
else
l = m;
}
return r;
}
static int f(int A[], int size)
{
// Add boundary case, when array size is one
int[] tailTable = new int[size];
int len; // always points empty slot
tailTable[0] = A[0];
len = 1;
for (int i = 1; i < size; i++) {
if (A[i] < tailTable[0])
// new smallest value
tailTable[0] = A[i];
else if (A[i] > tailTable[len - 1])
// A[i] wants to extend largest subsequence
tailTable[len++] = A[i];
else
// A[i] wants to be current end candidate of an existing
// subsequence. It will replace ceil value in tailTable
tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
}
return len;
}
static int containsBoth(char X[],int N)
{
for(int i=1; i<N; i++)if(X[i]!=X[i-1])return i-1;
return -1;
}
static void f(char X[],int N,int A[])
{
int c=0;
for(int i=N-1; i>=0; i--)
{
if(X[i]=='1')
{
A[i]=c;
}
else c++;
A[i]+=A[i+1];
}
}
static int f(int i,int j,char X[],char Y[],int zero)
{
if(i==X.length && j==Y.length)return 0;
if(i==X.length)return iv_B[j]; //return inversion count here
if(j==Y.length)return iv_A[i];
if(dp[i][j]==-1)
{
int cost_x=0,cost_y=0;
if(X[i]=='1')
{
cost_x=zero+f(i+1,j,X,Y,zero);
}
else cost_x=f(i+1,j,X,Y,zero-1);
if(Y[j]=='1')
{
cost_y=zero+f(i,j+1,X,Y,zero);
}
else cost_y=f(i,j+1,X,Y,zero-1);
dp[i][j]=Math.min(cost_x, cost_y);
}
return dp[i][j];
}
static boolean f(long last,long next,long l,long r,long A,long B)
{
while(l<=r)
{
long m=(l+r)/2;
long s=((m)*(m-1))/2;
long l1=(A*m)+s,r1=(m*B)-s;
if(Math.min(next, r1)<Math.max(last, l1))
{
if(l1>last)r=m-1;
else l=m+1;
}
else return true;
}
return false;
}
static boolean isVowel(char x)
{
if(x=='a' || x=='e' || x=='i' ||x=='u' || x=='o')return true;
return false;
}
static boolean f(int i,int j)
{
//i is no of one
//j is no of ai>1
if(i==0 && j==0)return true; //this player has no pile to pick --> last move iska rha hoga
if(dp[i][j]==-1)
{
boolean f=false;
if(i>0)
{
if(!f(i-1,j))f=true;
}
if(j>0)
{
if(!f(i,j-1) && !f(i+1,j-1))f=true;
}
if(f)dp[i][j]=1;
else dp[i][j]=0;
}
return dp[i][j]==1;
}
static int last=-1;
static void dfs(int n,int p)
{
last=n;
System.out.println("n--> "+n+" p--> "+p);
for(int c:g[n])
{
if(c!=p)dfs(c,n);
}
}
static long abs(long a,long b)
{
return Math.abs(a-b);
}
static int lower(long A[],long x)
{
int l=0,r=A.length;
while(r-l>1)
{
int m=(l+r)/2;
if(A[m]<=x)l=m;
else r=m;
}
return l;
}
static int f(int i,int s,int j,int N,int A[],HashMap<Integer,Integer> mp)
{
if(i==N)
{
return s;
}
if(dp[i][j]==-1)
{
if(mp.containsKey(A[i]))
{
int f=mp.get(A[i]);
int c=0;
if(f==1)c++;
mp.put(A[i], f+1);
HashMap<Integer,Integer> temp=new HashMap<>();
temp.put(A[i],1);
return dp[i][j]=Math.min(f(i+1,s+1+c,j,N,A,mp), s+K+f(i+1,0,i,N,A,temp));
}
else
{
mp.put(A[i],1);
return dp[i][j]=f(i+1,s,j,N,A,mp);
}
}
return dp[i][j];
}
static boolean inRange(int a,int l,int r)
{
if(l<=a && r>=a)return true;
return false;
}
static long f(long a,long b)
{
if(a%b==0)return a/b;
else return (a/b)+f(b,a%b);
}
static void f(int index,long A[],int i,long xor)
{
if(index+1==A.length)
{
if(valid(xor^A[index],i))
{
xor=xor^A[index];
max=Math.max(max, i);
}
return;
}
if(dp[index][i]==0)
{
dp[index][i]=1;
if(valid(xor^A[index],i))
{
f(index+1,A,i+1,0);
f(index+1,A,i,xor^A[index]);
}
else
{
f(index+1,A,i,xor^A[index]);
}
}
}
static boolean valid(long xor,int i)
{
if(xor==0)return true;
while(xor%2==0 )
{
xor/=2;
i--;
}
return i<=0;
}
static int next(int i,long pre[],long S)
{
int l=i,r=pre.length;
while(r-l>1)
{
int m=(l+r)/2;
if(pre[m]-pre[i-1]>S)r=m;
else l=m;
}
return r;
}
static boolean lexo(long A[],long B[])
{
for(int i=0; i<A.length; i++)
{
if(B[i]>A[i])return true;
if(A[i]>B[i])return false;
}
return false;
}
static long [] f(long A[],long B[],int j)
{
int N=A.length;
long X[]=new long[N];
for(int i=0; i<N; i++)
{
X[i]=(B[j]+A[i])%N;
j++;
j%=N;
}
return X;
}
static int find(int a)
{
if(par[a]<0)return a;
return par[a]=find(par[a]);
}
static void union(int a,int b)
{
b=find(b);
a=find(a);
if(a!=b)
{
par[b]=a;
}
}
static void print(char A[])
{
for(char c:A)System.out.print(c+" ");
System.out.println();
}
static void print(boolean A[])
{
for(boolean c:A)System.out.print(c+" ");
System.out.println();
}
static void print(int A[])
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static void print(long A[])
{
for(long i:A)System.out.print(i+ " ");
System.out.println();
}
static void print(ArrayList<Integer> A)
{
for(int a:A)System.out.print(a+" ");
System.out.println();
}
static long lower_Bound(long A[],int low,int high, long x)
{
if (low > high)
if (x >= A[high])
return A[high];
int mid = (low + high) / 2;
if (A[mid] == x)
return A[mid];
if (mid > 0 && A[mid - 1] <= x && x < A[mid])
return A[mid - 1];
if (x < A[mid])
return lower_Bound( A, low, mid - 1, x);
return lower_Bound(A, mid + 1, high, x);
}
static void sort(long[] a) //check for long
{
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static void setGraph(int N)
{
size=new int[N+1];
// D=new int[N+1];
g=new ArrayList[N+1];
for(int i=0; i<=N; i++)
{
g[i]=new ArrayList<>();
}
}
static long pow(long a,long b)
{
long pow=1L;
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(int 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 void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
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 GCD(long a,long b)
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static int[] input(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 6203ba307df8b1315aa3290b7ca77f07 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.lang.reflect.AnnotatedArrayType;
import java.util.*;
public class Main {
private static final MyWriter writer = new MyWriter();
private static final MyReader scan = new MyReader();
public static void main(String[] args) throws IOException {
int q = scan.nextInt(); while (q-- > 0)
solve(); writer.close();
}
private static void solve() throws IOException {
int n = scan.nextInt();
long[] arr = new long[n+1];
for(int i = 1; i <= n; i++){
arr[i] = scan.nextInt();
}
int res = 0;
for(int i = 1; i <= n; i++){
for(int j = (int)arr[i] - i ; j <= n ; j += arr[i]) {
if (j <= i) continue;
if (arr[i] * arr[j] == i + j) res ++;
}
}
writer.println(res);
}
}
class MyWriter implements Closeable {
private BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
public void print(Object object) throws IOException { writer.write(object.toString()); }
public void println(Object object) throws IOException { writer.write(object.toString());writer.write(System.lineSeparator()); }
public void close() throws IOException { writer.close(); }
}
class MyReader {
private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private StringTokenizer tokenizer = new StringTokenizer("");
private String innerNextLine() { try { return reader.readLine(); } catch (IOException ex) { return null;}}
public boolean hasNext() { while (!tokenizer.hasMoreTokens()) { String nextLine = innerNextLine();if (nextLine == null) return false;tokenizer = new StringTokenizer(nextLine); }return true; }
public String nextLine() { tokenizer = new StringTokenizer("");return innerNextLine(); }
public String next() { hasNext();return tokenizer.nextToken(); }
public int nextInt() { return Integer.parseInt(next()); }
public long nextLong() { return Long.parseLong(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | a317ab9a6ec21f9b41995d965ae08f96 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //import java.util.*;
//import java.lang.*;
//import java.io.*;
//
//
//public class Codeforces
//{
// public static void main (String[] args) throws Exception
// {
//
// BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
// BufferedWriter write = new BufferedWriter(new OutputStreamWriter(System.out));
//
// long TestCases = Long.parseLong(read.readLine().trim());
//
// for (int Case = 0; Case < TestCases; Case++) {
//
//// String[] str = read.readLine().trim().split(" ");
// int n = Integer.parseInt(read.readLine().trim());
// int array[] = Arrays.stream(read.readLine().trim().split(" ")).mapToInt(Integer::parseInt).toArray();
//
// boolean[] visted = new boolean[n];
//// int[] baap = new int[n];
// HashSet<Integer> set = new HashSet<>();
//
// for (int i = 0; i < n; i++) {
// if(!visted[i]){
// visted[i] = true;
// set.add(i);
//// baap[i] = i;
// }
// for (int j = i+1; j < n; j++) {
// if((j+1)-(i+1) != array[j]-array[i]){
// if(visted[j]){
// set.remove(i);
// }
// visted[j] = true;
//// baap[j] = baap[i];
// }
// }
// }
//
// write.write(set.size()+"\n");
//
//
// }
//
// write.flush();
// write.close();
// read.close();
// }
//
//
//}
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codeforces
{
public static void main (String[] args) throws Exception
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter write = new BufferedWriter(new OutputStreamWriter(System.out));
// Scanner scanner = new Scanner(System.in);
long TestCases = Long.parseLong(read.readLine());
for (int Case = 0; Case < TestCases; Case++) {
long n = Integer.parseInt(read.readLine().trim());
int[] array = Arrays.stream(read.readLine().trim().split(" ")).mapToInt(Integer::parseInt).toArray();
long count = 0;
for (int i = 0; i < n; i++) {
int j = array[i] -i-2;
for (; j < n; j+=array[i]) {
if(j>i && (long) array[i]*array[j] == (long)i+j+2)
count++;
}
}
write.write(count + "\n");
}
write.flush();
write.close();
read.close();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | befd014606623039fc7133c489de0672 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Practice {
public static void main(String[] args) {
FastReader sc = new FastReader();
int n = sc.nextInt();
while(n-->0) {
int x = sc.nextInt();
pair aa[] = new pair[x];
for(int i = 0 ; i < x; i++) {
int first = sc.nextInt();
int second = i+1;
aa[i] = new pair(first, second);
}
Arrays.sort(aa);
int cnt = 0;
for(int j = 0 ; j < x-1; j++) {
for(int i = j+1; i < x; i++) {
if((long)((Integer)aa[i].first * (Integer)aa[j].first) == ((Integer)aa[i].second + (Integer)aa[j].second)) cnt++;
if((long)(Integer)aa[i].first * (Integer)aa[j].first > (2*x-1)) break;
}
}
System.out.println(cnt);
}
}
// INPUT Class ---------->
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
}
// Pair Class ----------->
static class pair<T> implements Comparable<pair>{
T first, second;
pair(T first, T second) {
this.first = first;
this.second = second;
}
@Override
public int compareTo(pair o) {
return (Integer) this.first - (Integer) o.first;
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 8348b177596ddfac706e067df00d7ba4 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException{
FastReader fr = new FastReader();
PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
int t = fr.nextInt();
while (t-- > 0) {
int n = fr.nextInt();
int[] arr = new int[n+1];
int ans = 0;
for (int i = 1; i < arr.length; i++) {
arr[i] = fr.nextInt();
}
// I mean, this is pretty much just a better way of implementing my original idea, which I am happy that I thought of
for (int i = 1; i <= n; i++) {
for (int j = arr[i] - (i % arr[i]); j <= n; j+=arr[i]) {
if (i > j && i + j == arr[i] * arr[j]) ans++;
}
}
pr.println(ans);
}
pr.close();
}
static class Pair {
int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
static int toInt(String s) {
return Integer.parseInt(s);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader() throws FileNotFoundException
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 326ef667ba7f60c52338645816d6c3bd | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Trials1
{
public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(inp.readLine());
while(t-- >0)
{
int n=Integer.parseInt(inp.readLine());
String s[]=inp.readLine().split(" ");
int a[]=new int[n+1];
for(int i=0;i<n;i++)
{
a[i+1]=Integer.parseInt(s[i]);
}
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=a[i]-(i%a[i]);j<=n;j+=a[i])
{
if(i>j && a[i]*a[j]==i+j)
cnt++;
}
}
out.write(Integer.toString(cnt)+"\n");
}
out.flush();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 335e039cda68b14ced2a8dd8ce47e0c4 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Trials1
{
public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(inp.readLine());
while(t-- >0)
{
int n=Integer.parseInt(inp.readLine());
String s[]=inp.readLine().split(" ");
int a[]=new int[n+1];
for(int i=0;i<n;i++)
{
a[i+1]=Integer.parseInt(s[i]);
}
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=a[i]-(i%a[i]);j<=n;j+=a[i])
{
if(i>j && a[i]*a[j]==i+j)
cnt++;
}
}
out.write(Integer.toString(cnt)+"\n");
}
out.flush();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 3ecc91ebd098df1c8677541df5aab973 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Trials1
{
public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(inp.readLine());
while(t-- >0)
{
int n=Integer.parseInt(inp.readLine());
String s[]=inp.readLine().split(" ");
int a[]=new int[n+1];
for(int i=0;i<n;i++)
{
a[i+1]=Integer.parseInt(s[i]);
}
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=a[i]-(i%a[i]);j<=n;j+=a[i])
{
if(i>j && a[i]*a[j]==i+j)
cnt++;
}
}
out.write(Integer.toString(cnt)+"\n");
}
out.flush();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 3aeaa323a2941d9ede9ffdf448f7f00d | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Pleasant_Pairs {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
long[] A = new long[n+1];
for(int i = 1 ; i <= n ; i++) {
A[i] = sc.nextLong();
}
int count=0;
for(int i = 1 ; i <= n ; i++) {
for(long j = A[i]-i ; j <= n ; j += A[i]) {
if(j > 0) {
if(A[i] * A[(int)j] == i+j && i < j) {
count++;
}
}
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 5954a8f85403824b50cb405b1fa43041 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class javaTemplate {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for (int tt = 0; tt < t; tt += 1) {
int n = s.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);
for (int i = 1; i <= n; i += 1) {
arr.add(s.nextInt());
}
int ans = 0;
ArrayList<ArrayList<Integer>> find = new ArrayList<ArrayList<Integer>>();
for (int i = 1; i <= n; i += 1) {
int multi = 1;
while (true) {
int num = Math.abs((arr.get(i) * multi) - i);
if (num <= n) {
if (num > i) {
find.add(new ArrayList<Integer>(Arrays.asList(multi, num)));
}
} else {
break;
}
multi += 1;
}
}
for (int i = 0; i < find.size(); i += 1) {
int index = find.get(i).get(1);
int num = find.get(i).get(0);
if (arr.get(index) == num) {
ans += 1;
}
}
System.out.println(ans);
}
s.close();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | e60852a79d1b3e795e0fdc96dd99ea16 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class javaTemplate {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for (int tt = 0; tt < t; tt += 1) {
int n = s.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);
for (int i = 1; i <= n; i += 1) {
arr.add(s.nextInt());
}
int ans = 0;
ArrayList<ArrayList<Integer>> find = new ArrayList<ArrayList<Integer>>();
for (int i = 1; i <= n; i += 1) {
int multi = 1;
while (true) {
int num = Math.abs((arr.get(i) * multi) - i);
if (num <= n) {
if (num > i) {
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(multi);
temp.add(num);
find.add(temp);
}
} else {
break;
}
multi += 1;
}
}
for (int i = 0; i < find.size(); i += 1) {
int index = find.get(i).get(1);
int num = find.get(i).get(0);
if (arr.get(index) == num) {
ans += 1;
}
}
System.out.println(ans);
}
s.close();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 463426c0485da7041547a8f57e7a475f | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
// import java.io.*;
import java.util.*;
public class javaTemplate {
public static void main(String[] args) {
Scanner fs = new Scanner(System.in);
// StringBuilder output = new StringBuilder();
int t = fs.nextInt();
for (int tt = 0; tt < t; tt += 1) {
int n = fs.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);
for (int i = 1; i <= n; i += 1) {
arr.add(fs.nextInt());
}
int ans = 0;
ArrayList<ArrayList<Integer>> find = new ArrayList<ArrayList<Integer>>();
for (int i = 1; i <= n; i += 1) {
int multi = 1;
while (true) {
int num = Math.abs((arr.get(i) * multi) - i);
if (num <= n) {
if (num > i) {
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(multi);
temp.add(num);
find.add(temp);
}
} else {
break;
}
multi += 1;
}
}
for (int i = 0; i < find.size(); i += 1) {
int index = find.get(i).get(1);
int num = find.get(i).get(0);
if (arr.get(index) == num) {
ans += 1;
}
}
System.out.println(ans);
// output.append(ans).append('\n');
}
// System.out.println(output.toString());
fs.close();
}
}
// class FastScanner {
// BufferedReader br;
// StringTokenizer st;
// public FastScanner() {
// br = new BufferedReader(new InputStreamReader(System.in));
// }
// String next() {
// while (st == null || !st.hasMoreElements()) {
// try {
// st = new StringTokenizer(br.readLine());
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// return st.nextToken();
// }
// int nextInt() {
// return Integer.parseInt(next());
// }
// long nextLong() {
// return Long.parseLong(next());
// }
// double nextDouble() {
// return Double.parseDouble(next());
// }
// String nextLine() {
// String str = "";
// try {
// str = br.readLine();
// } catch (IOException e) {
// e.printStackTrace();
// }
// return str;
// }
// } | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 7522a25872052878f3d664917dec14f8 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class javaTemplate {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
StringBuilder output = new StringBuilder();
int t = fs.nextInt();
for (int tt = 0; tt < t; tt += 1) {
int n = fs.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);
for (int i = 1; i <= n; i += 1) {
arr.add(fs.nextInt());
}
int ans = 0;
ArrayList<ArrayList<Integer>> find = new ArrayList<ArrayList<Integer>>();
for (int i = 1; i <= n; i += 1) {
int multi = 1;
while (true) {
int num = Math.abs((arr.get(i) * multi) - i);
if (num <= n) {
if (num > i) {
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(multi);
temp.add(num);
find.add(temp);
}
} else {
break;
}
multi += 1;
}
}
for (int i = 0; i < find.size(); i += 1) {
int index = find.get(i).get(1);
int num = find.get(i).get(0);
if (arr.get(index) == num) {
ans += 1;
}
}
output.append(ans).append('\n');
}
System.out.println(output.toString());
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c434a39d7fcf5698ef4ad27bae1770a7 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class javaTemplate {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
StringBuilder output = new StringBuilder();
int t = fs.nextInt();
for (int tt = 0; tt < t; tt += 1) {
int n = fs.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);
for (int i = 1; i <= n; i += 1) {
arr.add(fs.nextInt());
}
int ans = 0;
ArrayList<ArrayList<Integer>> find = new ArrayList<ArrayList<Integer>>();
for (int i = 1; i <= n; i += 1) {
int multi = 1;
while (true) {
int num = Math.abs((arr.get(i) * multi) - i);
if (num <= n) {
if (num > i) {
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(multi);
temp.add(num);
find.add(temp);
}
} else {
break;
}
multi += 1;
}
}
for (int i = 0; i < find.size(); i += 1) {
int index = find.get(i).get(1);
int num = find.get(i).get(0);
if (arr.get(index) == num) {
ans += 1;
}
}
output.append(ans).append('\n');
}
System.out.println(output.toString());
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 5b4916d9c218cc994cb22a71a7149deb | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class javaTemplate {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int t = fs.nextInt();
StringBuilder allAns = new StringBuilder();
for (int tt = 0; tt < t; tt += 1) {
int n = fs.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);
for (int i = 1; i <= n; i += 1) {
arr.add(fs.nextInt());
}
int ans = 0;
ArrayList<ArrayList<Integer>> find = new ArrayList<ArrayList<Integer>>();
for (int i = 1; i <= n; i += 1) {
int multi = 1;
while (true) {
int num = Math.abs((arr.get(i) * multi) - i);
if (num <= n) {
if (num > i) {
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(multi);
temp.add(num);
find.add(temp);
}
} else {
break;
}
multi += 1;
}
}
for (int i = 0; i < find.size(); i += 1) {
// System.out.println(find.get(i));
int index = find.get(i).get(1);
int num = find.get(i).get(0);
if (arr.get(index) == num) {
ans += 1;
}
}
allAns.append(ans).append('\n');
}
System.out.println(allAns);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c73b378df7d17d680405b78c9755651c | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.Scanner;
public class pleasentPairs {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
}
long res = 0;
for (int i = 1; i < n; i++) {
for (int j = a[i] - i; j <= n; j += a[i]) {
if (j >= 1) {
if (((long) a[i] * a[j] == i + j) && (i < j)) {
res++;
}
}
}
}
System.out.println(res);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | a4d04b2da5b0f55aabc93a7f2db1fc5c | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.Scanner;
public class pleasentPairs {
public static void main(String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
int a[] = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
}
long c = 0;
for (int i = 1; i < n; i++) {
for (int j = a[i] - i; j <= n; j += a[i]) {
if (j >= 1)
if (((long) a[i] * a[j] == i + j) && (i < j))
c++;
}
}
System.out.println(c);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 827b05ca37d3ff28bc650ee52d53558b | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.sql.SQLOutput;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
static StringBuilder ANS;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
}
static void solve(){
int n = sc.nextInt();
int[] arr = new int[n+1];
for (int i = 1; i <= n; i++)
arr[i] = sc.nextInt();
int c = 0;
for(int i=1;i<=n;i++){
for(int j=arr[i]-i;j<=n;j+=arr[i]){
if(i < j && ((long) arr[i] * arr[j]) == i+j) {
c++;
}
}
}
ANS.append(c).append("\n");
}
private static final FastReader sc = new FastReader();
public static void main (String[] args) throws java.lang.Exception {
int t = sc.nextInt();
ANS = new StringBuilder();
while(t-- != 0)
solve();
System.out.println(ANS);
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | e8b762e9a82ddcb7bda31cccfea91bc2 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] a=new int[n];
Map<Integer,Integer> map=new HashMap<>();
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
map.put(a[i],i+1);
}
Arrays.sort(a);
int count=0;
for(int i=0;i<n-1;i++)
{
if(a[i]*a[i+1]>2*n-1)
break;
for(int j=i+1;j<n;j++){
if(a[i]*a[j]>2*n-1)
break;
if(a[i]*a[j]==map.get(a[i])+map.get(a[j]))
count++;
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0c9969f8bc0523de87a7be9e55031919 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.Arrays;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;
import static java.lang.Math.abs;
import static java.lang.Math.random;
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.MIN_VALUE;
import static java.util.Collections.reverseOrder;
public final class Test1 {
static int mod = 1000000007;
static int mod1 = 998244353;
public static void main(String[] args) {
solve();
}
static long gcd(int a, int b) {if (b == 0) return a; return gcd(b, a % b); }
static long modAdd(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
static long modMul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
static long modSub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
static long modDiv(long a, long b, long m) {a = a % m; b = b % m; return (modMul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
static long mminvprime(long a, long b) {return expo(a, b - 2, b);}
static long expo(long a, long b, long mod) {long res = 1; while (b > 0) {if ((b & 1) != 0)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
static long setBits(int n) {int cnt = 0; while (n != 0) { cnt++; n = n & (n - 1); } return cnt;}
static int[] sieve(int n) {int[] arr = new int[n + 1]; for (int i = 2; i <= n; i++)if (arr[i] == 0) {for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return arr;}
static void debug(int[] nums) { for (int i = 0; i < nums.length; i++) System.out.println(nums[i] + " "); }
static void debug(long[] nums) { for (int i = 0; i < nums.length; i++) System.out.println(nums[i] + " "); }
static void debug(String[] nums) { for (int i = 0; i < nums.length; i++) System.out.println(nums[i] + " "); }
static void reverse(int[] nums) { int start = 0, end = nums.length - 1; while (start < end) {int temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; start++; end--; } }
static void reverse(char[] nums) { int start = 0, end = nums.length - 1; while (start < end) {char temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; start++; end--; } }
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 nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
// <------------------------- CODE START FROM HERE -------------------------------->
public static void solve() {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while (t-- != 0) {
int n = sc.nextInt();
int arr[] = sc.readArray(n);
if (n == 2) {
if ( (arr[0] * arr[1]) == 3)
System.out.println(1);
else
System.out.println(0);
} else {
Pair nums[] = new Pair[n];
for (int i = 0; i < n; i++) {
nums[i] = new Pair(arr[i], i + 1);
}
Arrays.sort(nums);
// for (int i = 0; i < n; i++)
// System.out.println(nums[i]);
long ans = 0;
int itr = 0;
while ((nums[itr].val * nums[itr + 1].val ) <= (2 * n - 1))
itr++;
for (int i = 0; i < itr; i++)
for (int j = i + 1; j < n; j++)
if ((nums[i].val * nums[j].val) == ( nums[i].index + nums[j].index) )
ans++;
System.out.println(ans);
}
}
}
static class Pair implements Comparable<Pair> {
long val, index;
Pair(long val, long index) {
this.val = val;
this.index = index;
}
public int compareTo(Pair p) {
return (int)(this.val - p.val);
}
public String toString() {
return val + " " + index;
}
}
// <----------------------------------CODE END HERE------------------------>
// System.out.println();
// int b[] = a.clone();
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 4ceb361398ce23104d2faa01b317a81b | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.Math;
public class Main{
static BufferedReader reader;
static StringTokenizer tokenizer;
static PrintWriter writer;
static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
static String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static String nexts() throws IOException {
tokenizer = new StringTokenizer(reader.readLine());
String s="";
while (tokenizer.hasMoreTokens()) {
s+=tokenizer.nextElement()+" ";
}
return s;
}
public static int gcd(int x, int y){
if (y == 0) return x; else return gcd(y, x % y);
}
public static long gcd(long x, long y){
if (y == 0) return x; else return gcd(y, x % y);
}
static long digitSum(String x) {
long a = 0;
for (int i = 0; i < x.length(); i++) {
a += x.charAt(i) - '0';
}
return a;
}
static long digitSum(long x) {
long a = 0;
while (x > 0) {
a += x % 10;
x /= 10;
}
return a;
}
static int max(int x, int y) {
return Math.max(x, y);
}
static int min(int x, int y) {
return Math.min(x, y);
}
static int max(int x, int y, int z) {
x = Math.max(x, y);
x = Math.max(x, z);
return x;
}
static int min(int x, int y, int z) {
x = Math.min(x, y);
x = Math.min(x, z);
return x;
}
static long max(long x, long y) {
return Math.max(x, y);
}
static long min(long x, long y) {
return Math.min(x, y);
}
static long max(long x, long y, long z) {
x = Math.max(x, y);
x = Math.max(x, z);
return x;
}
static long min(long x, long y, long z) {
x = Math.min(x, y);
x = Math.min(x, z);
return x;
}
static double max(double x, double y) {
return Math.max(x, y);
}
static double min(double x, double y) {
return Math.min(x, y);
}
static double max(double x, double y, double z) {
x = Math.max(x, y);
x = Math.max(x, z);
return x;
}
static double min(double x, double y, double z) {
x = Math.min(x, y);
x = Math.min(x, z);
return x;
}
static void rsort(int[] ar) {
Arrays.sort(ar);
int len = ar.length;
for (int i = 0; i < len / 2; i++) {
int tmp = ar[i];
ar[i] = ar[len - 1 - i];
ar[len - 1 - i] = tmp;
}
}
static void rsort(long[] ar) {
Arrays.sort(ar);
int len = ar.length;
for (int i = 0; i < len / 2; i++) {
long tmp = ar[i];
ar[i] = ar[len - 1 - i];
ar[len - 1 - i] = tmp;
}
}
static void rsort(double[] ar) {
Arrays.sort(ar);
int len = ar.length;
for (int i = 0; i < len / 2; i++) {
double tmp = ar[i];
ar[i] = ar[len - 1 - i];
ar[len - 1 - i] = tmp;
}
}
static void rsort(char[] ar) {
Arrays.sort(ar);
int len = ar.length;
for (int i = 0; i < len / 2; i++) {
char tmp = ar[i];
ar[i] = ar[len - 1 - i];
ar[len - 1 - i] = tmp;
}
}
static long lcm(long a, long b) throws IOException {
return a * b / gcd(a, b);
}
static int lcm(int a, int b) throws IOException {
return a * b / gcd(a, b);
}
static int rev(int x) {
int a = 0;
while (x > 0) {
a = a * 10 + x % 10;
x /= 10;
}
return a;
}
public static boolean isPrime(int nn)
{
if(nn<=1)return false;
if(nn<=3){return true; }
if (nn%2==0||nn%3==0){return false; }
for (int i=5;i*i<=nn;i=i+6){
if(nn%i==0||nn%(i+2)==0){return false; }}
return true;
}
public static void shuffle(int[] A) {
for (int i = 0; i < A.length; i++) {
int j = (int)(i * Math.random());
int tmp = A[i];A[i] = A[j];A[j] = tmp;
}
}
public static void shufflel(Long[] A) {
for (int i = 0; i < A.length; i++) {
int j = (int)(i * Math.random());
long tmp = A[i];A[i] = A[j];A[j] = tmp;
}
}
public static String reverse(String input)
{
StringBuilder input2=new StringBuilder();
input2.append(input);
input2 = input2.reverse();
return input2.toString();
}
public static long power(int x, long n)
{
// long mod = 1000000007;
if (n == 0) {
return 1;
}
long pow = power(x, n / 2);
if ((n & 1) == 1) {
return (x * pow * pow);
}
return (pow * pow);
}
public static long power(long x, long y, long p) //x^y%p
{
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % p;
}
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static long ncr(int n, int k)
{
long res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k) {
k = n - k;
}
// Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
public static int inv(int a, int m) //Returns modulo inverse of a with respect to m using extended euclid algorithm
{
int m0=m,t,q;
int x0=0,x1=1;
if(m==1){
return 0; }
while(a>1)
{
q=a/m;
t=m;
m=a%m;a=t;
t=x0;
x0=x1-q*x0;
x1=t; }
if(x1<0){
x1+=m0; }
return x1;
}
static int modInverse(int n, int p)
{
return (int)power((long)n, (long)(p - 2),(long)p);
}
static int ncrmod(int n, int r, int p)
{
if (r == 0) // Base case
return 1;
int[] fac = new int[n + 1]; // Fill factorial array so that we can find all factorial of r, n and n-r
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; //IMPORTANT
}
static int upper(int a[], int x) //Returns rightest index of x in sorted arr else -1
{ //If not present returns index of just smaller element
int n=a.length;
int l=0;
int r=n-1;
int ans=-1;
while(l<=r){
int m=(r-l)/2+l;
if(a[m]<=x){
ans=m;
l=m+1;
}
else{
r=m-1;
}
}
return ans;
}
static int lower(int a[], int x) //Returns leftest index of x in sorted arr else n
{ //If not present returns index of just greater element
int n=a.length;
int l=0;
int r=n-1;
int ans=n;
while(l<=r){
int m=(r-l)/2+l;
if(a[m]>=x){
ans=m;
r=m-1;
}
else{
l=m+1;
}
}
return ans;
}
public static long stringtoint(String s){ // Convert bit string to number
long a = 1;
long ans = 0;
StringBuilder sb = new StringBuilder();
sb.append(s);
sb.reverse();
s=sb.toString();
for(int i=0;i<s.length();i++){
ans = ans + a*(s.charAt(i)-'0');
a = a*2;
}
return ans;
}
String inttostring(long a,long m){ // a is number and m is length of string required
String res = ""; // Convert a number in bit string representation
for(int i=0;i<(int)m;i++){
if((a&(1<<i))==1){
res+='1';
}else
res+='0';
}
StringBuilder sb = new StringBuilder();
sb.append(res);
sb.reverse();
res=sb.toString();
return res;
}
static final int inf = Integer.MAX_VALUE / 2;
static final long linf = Long.MAX_VALUE / 3;
static final long mod = (long) 1e9 + 7;
static class R implements Comparable<R>{
long x, y;
public R(long x, long y) { //a[i]=new R(x,y);
this.x = x;
this.y = y;
}
public int compareTo(R o) {
return (int)(x-o.x); //Increasing order(Which is usually required)
}
}
//Check if palindrome string - System.out.print(A.equals(new StringBuilder(A).reverse().toString())?"Yes":"No");
public static void main(String[] args) throws IOException {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
}
//public static boolean check() {
//
// }
private static void solve() throws IOException {
int t = nextInt();
while(t-->0){
//String s= nextToken();
//String[] s = str.split("\\s+");
//ArrayList<Integer> ar=new ArrayList<Integer>();
//HashSet<Integer> set=new HashSet<Integer>();
// HashMap<Long,Long> h=new HashMap<Long,Long>();
//R[] a1=new R[n];
//char[] c=nextToken().toCharArray();
//PriorityQueue<Integer> pq=new PriorityQueue<Integer>(Collections.reverseOrder());
//NavigableSet<Integer> pq=new TreeSet<>();
int n = nextInt();
//long n = nextLong();
//int[] a=new int[n];
R[] a=new R[n];
//for(int i=0;i<=2*n;i++)b[i]=-1L;
for(int i=0;i<n;i++){
a[i] =new R(nextLong(),i);
}
//for(R p:a)writer.print(p.x+" "+p.y+" ");
long ans=0;
//shuffle(a);
//shufflel(a);rsort();
Arrays.sort(a);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if((long)(a[i].y+a[j].y+2)==(a[i].x*a[j].x))ans++;
if(a[i].x*a[j].x>(long)2*n)break;
}
}
writer.println(ans);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | ff08bc7e09191d370085af8713137833 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer=null;
public static void main(String[] args) throws IOException
{
new Main().execute();
}
void debug(Object...os)
{
System.out.println(Arrays.deepToString(os));
}
int ni() throws IOException
{
return Integer.parseInt(ns());
}
long nl() throws IOException
{
return Long.parseLong(ns());
}
double nd() throws IOException
{
return Double.parseDouble(ns());
}
String ns() throws IOException
{
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(br.readLine());
return tokenizer.nextToken();
}
String nline() throws IOException
{
tokenizer=null;
return br.readLine();
}
void execute() throws IOException
{
int t = ni();
while(t-- > 0){
solve();
}
}
void solve() throws IOException {
int n = ni();
int[] lookup = new int[2*n+1];
int[] arr = new int[n + 1];
int max = 0;
for(int i=1;i<=n;i++){
int num = ni();
arr[i] = num;
// max = Math.max(max, num);
// lookup[num] = i;
}
int count = 0;
for(int i=1;i<=n;i++){
for(int j=1;j * arr[i] <= 2*n;j++){
if(lookup[j] != 0 ){
long mul = (long)arr[i] * j;
long sum = i + (long)lookup[j];
count = mul == sum ? count + 1 : count;
}
}
lookup[arr[i]] = i;
}
System.out.println(count);
}
void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 86208dc7ab7339aeda3a8abb51c4eb16 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class ArrayQues {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc=new FastReader();
int k=sc.nextInt();
//
while(k-->0) {
int n=sc.nextInt();
int A[]=new int[n+1];
HashMap<Integer,Integer> map =new HashMap<>();
for(int i=1; i<=n; i++) {
A[i]=sc.nextInt();
}
int res = 0;
for (int i = 1; i <= n; i++) {
int num = A[i];
for (int val = 1; val * num <= 2 * n; val++) {
if (map.containsKey(val) && map.get(val) + i == A[i] * val) res++;
}
map.put(A[i],i);
}
System.out.println(res);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0415c9b5bd742abbbfd026b77d4744a7 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.*;import java.util.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readChar() throws IOException {
return next().charAt(0);
}
static String readLine() throws IOException {
return br.readLine();
}
static class Pair implements Comparable<Pair> {
int f, s;
Pair(int f, int s) {
this.f = f; this.s = s;
}
public int compareTo(Pair other) {
if (this.f != other.f) return this.f - other.f;
return this.s - other.s;
}
}
public static void main(String[] args) throws IOException {
int t = readInt();
while(t-- > 0) {
int n = readInt();
Pair[] p = new Pair[n];
for(int i = 0; i < n; ++i) p[i] = new Pair(readInt(),i+1);
Arrays.sort(p);
int ret = 0;
for(int i = 0; i < n; ++i) {
for(int j = i+1; j < n; ++j) {
long pro = (long)p[i].f*p[j].f;
if(pro >= (n<<1)) break;
if(pro == p[i].s+p[j].s) ++ret;
}
}
System.out.println(ret);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | d00fc3f67538f6cc6dbe0937765734da | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readChar() throws IOException {
return next().charAt(0);
}
static String readLine() throws IOException {
return br.readLine();
}
static class Pair implements Comparable<Pair> {
int f, s;
Pair(int f, int s) {
this.f = f; this.s = s;
}
public int compareTo(Pair other) {
if (this.f != other.f) return this.f - other.f;
return this.s - other.s;
}
}
public static void main(String[] args) throws IOException {
for (int t = readInt(); t > 0; --t) {
int n = readInt();
Pair p[] = new Pair[n + 1];
for (int i = 1; i <= n; ++i)
p[i] = new Pair(readInt(), i);
Arrays.sort(p, 1, n + 1);
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
long pro = (long)p[i].f*p[j].f;
if (pro >= n<<1) break;
if (pro == p[i].s + p[j].s) ++ans;
}
}
System.out.println(ans);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b3059a1a87150f5701540763cb0c2d16 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | // Piyush Nagpal
import java.util.*;
import java.io.*;
public class C{
static int MOD=1000000007;
static PrintWriter pw;
static FastReader sc;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble(){return Double.parseDouble(next());}
public char nextChar() throws IOException {return next().charAt(0);}
String nextLine(){
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] intArr(int n) throws IOException {int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();return in;}
public long[] longArr(int n) throws IOException {long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();return in;}
}
public static long gcd(long a,long b){if( b>a ){return gcd(b,a);}if( b==0 ){return a;} return gcd(b,a%b);}
public static long expo( long a,long b,long M ){long result=1;while(b>0){if( b%2==1 ){result=(result*a)%M;}a=(a*a)%M;b=b/2;}return result%M;}
public static ArrayList<Long> Sieve(int n){boolean [] arr= new boolean[n+1];Arrays.fill(arr, true);ArrayList<Long> list= new ArrayList<>();for(int i=2;i<=n;i++){if( arr[i]==true ){list.add((long)i);}for(int j=2*i;j<=n;j+=i){arr[j]=false;}}return list;}
public static void printarr(int [] arr){for(int i=0;i<arr.length;i++){pw.print(arr[i]+" ");}}
public static void printarr(long [] arr){for(int i=0;i<arr.length;i++){pw.print(arr[i]+" ");}}
// int [] arr=sc.intArr(n);
static void solve() throws Exception{
int n =sc.nextInt();
long [] arr= new long [n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
long count=0;
for(int i=1;i<=n;i++){
long x= arr[i-1];
int k=(int)(x-i);
while(k<=i){
k+=x;
}
if(x==1){
for(int j=k;j<=n;j++){
if( arr[i-1]*arr[j-1]==i+j ){
count++;
}
}
}else{
for(int j=k;j<=n;j+=x){
if( arr[i-1]*arr[j-1]==i+j ){
count++;
}
}
}
}
pw.println(count);
}
public static void main(String[] args) throws Exception{
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {
System.err.println("Error");
}
sc= new FastReader();
pw = new PrintWriter(System.out);
int tc=1;
tc=sc.nextInt();
for(int i=1;i<=tc;i++) {
// pw.printf("Case #%d: "b, i);
solve();
}
pw.flush();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | ccb4ef2c25c11c54abbcc0ae29ad041c | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | // Piyush Nagpal
import java.util.*;
import java.io.*;
public class C{
static int MOD=1000000007;
static PrintWriter pw;
static FastReader sc;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble(){return Double.parseDouble(next());}
public char nextChar() throws IOException {return next().charAt(0);}
String nextLine(){
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] intArr(int n) throws IOException {int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();return in;}
public long[] longArr(int n) throws IOException {long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();return in;}
}
public static long gcd(long a,long b){if( b>a ){return gcd(b,a);}if( b==0 ){return a;} return gcd(b,a%b);}
public static long expo( long a,long b,long M ){long result=1;while(b>0){if( b%2==1 ){result=(result*a)%M;}a=(a*a)%M;b=b/2;}return result%M;}
public static ArrayList<Long> Sieve(int n){boolean [] arr= new boolean[n+1];Arrays.fill(arr, true);ArrayList<Long> list= new ArrayList<>();for(int i=2;i<=n;i++){if( arr[i]==true ){list.add((long)i);}for(int j=2*i;j<=n;j+=i){arr[j]=false;}}return list;}
public static void printarr(int [] arr){for(int i=0;i<arr.length;i++){pw.print(arr[i]+" ");}}
public static void printarr(long [] arr){for(int i=0;i<arr.length;i++){pw.print(arr[i]+" ");}}
// int [] arr=sc.intArr(n);
static void solve() throws Exception{
int n =sc.nextInt();
long [] arr= new long [n+1];
for(int i=1;i<=n;i++){
arr[i]=sc.nextLong();
}
long count=0;
for(int i=1;i<=n-1;i++){
long x= arr[i];
int j=(int)(x-i);
while(j<=i){
j+=x;
}
for(;j<=n;j+=x){
if( arr[i]*arr[j]==(i+j) ){
count++;
}
}
}
pw.println(count);
}
public static void main(String[] args) throws Exception{
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {
System.err.println("Error");
}
sc= new FastReader();
pw = new PrintWriter(System.out);
int tc=1;
tc=sc.nextInt();
for(int i=1;i<=tc;i++) {
// pw.printf("Case #%d: "b, i);
solve();
}
pw.flush();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0a4f7db88c5ec2e087bc504b345b729d | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
//import java.util.*;
public class Solution {
static class FastScanner {
BufferedReader br;
StringTokenizer st ;
FastScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
FastScanner(String file) {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
st = new StringTokenizer("");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("file not found");
e.printStackTrace();
}
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
String readLine() throws IOException{
return br.readLine();
}
}
public static void main(String[] args) throws Exception {
FastScanner s = new FastScanner();
int t = s.nextInt();
for(int q=0;q<t;q++){
int n = s.nextInt();
int arr[] = new int[n+1];
//Map<Integer,Integer> map = new HashMap<>();
int map1[] = new int[2*n + 1];
Arrays.fill(map1,(int)Math.pow(10,6));
for(int i=1;i<=n;i++){
arr[i] = s.nextInt();
//map.put(arr[i],i);
map1[arr[i]] = i;
}
int count = 0;
for(int i = 3;i<2*n;i++){
for(int j=1;j<=(int)(Math.sqrt(i));j++){
if((i%j==0) && (map1[j] + map1[i/j] == i) && (i!=j*j)){
count++;
}
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 92d44687dd787f4da04284f2401fada2 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Practice2 {
static long[] sort(long[] arr) {
long n=arr.length;
ArrayList<Long> al=new ArrayList<>();
for(int i=0;i<n;i++) {
al.add(arr[i]);
}
Collections.sort(al);
for(int i=0;i<n;i++) {
arr[i]=al.get(i);
}
return arr;
}
public static void main (String[] args) {
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
// out.print();
//out.println();
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++) {
arr[i]=sc.nextInt();
}
long count=0;
for(int i=1;i<=n;i++) {
for(int j=arr[i-1]-i;j<=n;j+=arr[i-1]) {
if(j-1>=0&&j>i) {
if((long)arr[i-1]*(long)arr[j-1]==i+j) count++;
}
}
}
out.println(count);
}
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c6a6c68c4481a24f40cd8e6ada459f89 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.lang.reflect.Array;
import java.math.*;
import java.net.Inet4Address;
import java.security.KeyStore;
import java.util.*;
public class sampleEditor_codeforces {
static int mod=1000000007;
static int mod2=1000003;
static Scanner sc = new Scanner(System.in);
static boolean [] sieve=new boolean[100000002];
static ArrayList<Integer> allPrimes=new ArrayList<>();
static void createSieve() {
sieve[1]=true;
sieve[0]=true;
for(int i=2;i*i<=100000001;i++) {
if(!sieve[i]) {
for(int j=i*i;j<=100000001;j+=i) {
sieve[j]=true;
}
}
}
// for(int i=2;i<=100000001;i++) {
// if(!sieve[i]) allPrimes.add(i);
// }
}
static class Pair implements Comparable<Pair>{
int x;
int y;
public Pair(int px , int py){
x = px;
y = py;
}
@Override
public int compareTo(Pair pair){
if (x > pair.x)
return 1;
else if (x == pair.x)
return 0;
else
return -1;
}
}
public static long gcd(long a,long b) {
if(b==0) return a;
return gcd(b,a%b);
}
public static long binaryToDecimal(String binary){
int n=binary.length();
int i=n-1;
long sum=0;
long two=1;
while(i>=0){
sum+=two*(binary.charAt(i)-'0')%mod2;
two*=2;
i--;
}
return sum;
}
public static boolean isSorted(int[] arr) {
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) {
return false;
}
}
return true;
}
public static void reverse(int[] arr) {
int l = 0;
int r = arr.length - 1;
while (l < r) {
int temp = arr[l];
arr[l] = arr[r];
arr[r] = temp;
l++;
r--;
}
}
public static void reverse(int[] arr,int l,int r) {
while (l < r) {
int temp = arr[l];
arr[l] = arr[r];
arr[r] = temp;
l++;
r--;
}
}
public static boolean isPalindrome(int n,int [] a,int x1){
int [] b=new int[n];
int m=0;
for(int i=0;i<n;i++){
if(a[i]!=x1){
b[m++]=a[i];
}
}
for(int i=0;i<m;i++){
if(b[i]!=b[m-1-i]){
return false;
}
}
return true;
}
public static long sumOfDigit(long num) {
return (num<10)?num:num%10+sumOfDigit(num/10);
}
public static void solve(int n,int [] a) {
int cnt=0;
for(int i =1;i<=n;i++) {
int x=a[i];
for(int j=x-i;j<=n;j+=x) {
if(j>=0){
if((long)x*a[j]==i+j && i<j) cnt++;
}
}
}
System.out.println(cnt);
}
public static void main(String args[]) {
// Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n=sc.nextInt();
int [] a=new int[n+1];
for(int i=1;i<=n;i++) {
a[i]=sc.nextInt();
}
solve(n,a);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c7c272396d8467e9891f9db321cacdd9 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import static java.lang.Math.*;
import java.io.*;
import java.math.*;
import java.util.*;
public class cf1 {
static FastReader x = new FastReader();
static OutputStream outputStream = System.out;
static PrintWriter out = new PrintWriter(outputStream);
/*---------------------------------------CODE STARTS HERE-------------------------*/
public static void main(String[] args) {
int t = x.nextInt();
StringBuilder str = new StringBuilder();
while (t > 0) {
int n= x.nextInt();
long a[] = new long[n+1];
for(int i=1;i<=n;i++) {
a[i] = x.nextLong();
}
long count=0;
for(int i=1;i<n;i++) {
long v=a[i];
for(int j=(int)v-i;j<=n;j+=v) {
if(j>i&&(v*a[j])==(i+j)) {
count++;
}
}
}
str.append(count);
str.append("\n");
t--;
}
out.println(str);
out.flush();
}
/*--------------------------------------------FAST I/O--------------------------------*/
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
char nextchar() {
char ch = ' ';
try {
ch = (char) br.read();
} catch (IOException e) {
e.printStackTrace();
}
return ch;
}
}
/*--------------------------------------------BOILER PLATE---------------------------*/
static int[] readarr(int n) {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = x.nextInt();
}
return arr;
}
static int[] sortint(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static long[] sortlong(long a[]) {
ArrayList<Long> al = new ArrayList<>();
for (long i : a) {
al.add(i);
}
Collections.sort(al);
for (int i = 0; i < al.size(); i++) {
a[i] = al.get(i);
}
return a;
}
static int pow(int x, int y) {
int result = 1;
while (y > 0) {
if (y % 2 == 0) {
x = x * x;
y = y / 2;
} else {
result = result * x;
y = y - 1;
}
}
return result;
}
static int[] revsort(int a[]) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a) {
al.add(i);
}
Collections.sort(al, Comparator.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = al.get(i);
}
return a;
}
static int[] gcd(int a, int b, int ar[]) {
if (b == 0) {
ar[0] = a;
ar[1] = 1;
ar[2] = 0;
return ar;
}
ar = gcd(b, a % b, ar);
int t = ar[1];
ar[1] = ar[2];
ar[2] = t - (a / b) * ar[2];
return ar;
}
static boolean[] esieve(int n) {
boolean p[] = new boolean[n + 1];
Arrays.fill(p, true);
for (int i = 2; i * i <= n; i++) {
if (p[i] == true) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
static ArrayList<Integer> primes(int n) {
boolean p[] = new boolean[n + 1];
ArrayList<Integer> al = new ArrayList<>();
Arrays.fill(p, true);
int i = 0;
for (i = 2; i * i <= n; i++) {
if (p[i] == true) {
al.add(i);
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
for (i = i; i <= n; i++) {
if (p[i] == true) {
al.add(i);
}
}
return al;
}
static int etf(int n) {
int res = n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
res /= i;
res *= (i - 1);
while (n % i == 0) {
n /= i;
}
}
}
if (n > 1) {
res /= n;
res *= (n - 1);
}
return res;
}
static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
static long gcd(long a, long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b3015a72243856130b0a791d82af55d6 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.Scanner;
public class Problem1541B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- >= 1) {
int n = sc.nextInt();
long arr[] = new long[n + 1];
for (int i = 1; i <= n; i++) {
arr[i] = sc.nextInt();
}
int count = 0;
for (int i = 1; i <= n; i++) {
for (long j = arr[i] - i; j <= n; j += arr[i]) {
if (j >= 0 && i<j) {
if (i + j == arr[i] * arr[(int) j]) {
count++;
}
}
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0f6fee4c360480eaddacf6174ceb4018 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import static java.lang.Math.*;
import java.io.*;
public class S {
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
while(test > 0){
test--;
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int a[] = new int[n];
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(st.nextToken());
}
solve(n, a);
//System.out.println(s + " " + tar);
//StringTokenizer st = new StringTokenizer(br.readLine());
//int n = Integer.parseInt(st.nextToken());
//int l = Integer.parseInt(st.nextToken());
//st = new StringTokenizer(br.readLine());
//int a[] = new int[n];
//for(int i = 0; i < n; i++){
// a[i] = Integer.parseInt(st.nextToken());
//}
}
}
final static int MOD = 1000000007;
public static void solve(int n, int a[]){
List<int[]> li = new ArrayList<int[]>();
for(int i = 0; i < n; i++){
li.add(new int[]{a[i], i+1});
}
Collections.sort(li, new Comparator<int[]>(){
public int compare(int i1[], int i2[]){
return i1[0] - i2[0];
}
});
int aa[][] = new int[n][2];
int ii = 0;
for(int val[] : li){
aa[ii][0] = val[0];
aa[ii++][1] = val[1];
}
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
long m = (long)aa[i][0] * (long)aa[j][0];
if(m == aa[i][1] + aa[j][1]){
ans++;
}
if(m > 2*n)break;
}
}
System.out.println(ans);
}
public static int gcd(int a, int b){
if(b == 0)return a;
return gcd(b, a%b);
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | e85f3b1700b95eed5abcaf5e8ece18fc | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class _1541B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] arr = new int[n+1];
for (int i = 1; i <=n; i++)
arr[i] = sc.nextInt();
int count=0;
for(int i=1;i<=n;i++){
for(int j=arr[i]-i;j<=n;j+=arr[i]) {
if (j >= 0 && (long) arr[i] * arr[j] == i + j && i < j)
count++;
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | fe96ff8f155da5423f7c63afb2192620 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class solver {
public static void main(String[] args) {
FastScanner read = new FastScanner();
if (System.getProperty("ONLINE_JUDGE") == null) {
try {
System.setOut(new PrintStream(new FileOutputStream("out.txt")));
read = new FastScanner("in.txt");
}
catch (Exception e) {
}
}
// START
int tc = read.nextInt();
while(tc-- > 0) {
int n = read.nextInt();
int[] a = new int[n+1];
for(int i = 1; i <= n; i++)
a[i] = read.nextInt();
long res = 0;
for(int i = 1; i < n; i++) {
for(int j = a[i]-i; j <= n; j+=a[i]) {
if((j >= 1) && (j > i) && (long)a[i]*a[j] == (i+j))
res++;
}
}
System.out.println(res);
}
// END
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
FastScanner(){}
FastScanner(String file_name) throws Exception {
br = new BufferedReader(new FileReader(file_name));
}
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 2aab6c0ed4e3f066275c2b1e1c2dba35 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
public class B_1541 {
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
public static void main(String ar[]) throws IOException {
Reader input = new Reader();
OutputWriter out = new OutputWriter(System.out);
int t = input.nextInt();
while (t-- > 0) {
int n = input.nextInt();
int a[] = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = input.nextInt();
}
long res = 0;
for (int i = 1; i < n; i++) {
for (int j = a[i] - i; j <= n; j += a[i]) {
if (j >= 1) {
if (((long) a[i] * a[j] == i + j) && (i < j)) {
res++;
}
}
}
}
out.printLine(res);
}
out.close();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b57cb0c740b78828e3546941e2d7b726 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class A728B {
public static void main(String[] args) {
JS scan = new JS();
int t = scan.nextInt();
while(t-->0){
int n = scan.nextInt();
int[] arr =new int[n];
for(int i = 0;i<n;i++){
arr[i] = scan.nextInt();
}
int count = 0;
for(int i = 0;i<n;i++){
int start = (arr[i]+(i+1) / arr[i] *arr[i]) - (i+1);
for(int j = start;j<=n;j+=arr[i]){
if(j-1<=i)continue;
long at = arr[j-1];
if(arr[i]*at==(i+1)+j){
// System.out.println((i+1) +" "+(j));
count++;
}
}
}
System.out.println(count);
}
}
static class JS {
public int BS = 1 << 16;
public char NC = (char) 0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public long nextLong() {
num = 1;
boolean neg = false;
if (c == NC) c = nextChar();
for (; (c < '0' || c > '9'); c = nextChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = nextChar()) {
res = (res << 3) + (res << 1) + c - '0';
num *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / num;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c > 32) {
res.append(c);
c = nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c != '\n') {
res.append(c);
c = nextChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = nextChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 5b1fba6e13e33326ea6f75a56850ee46 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class A728B {
public static void main(String[] args) {
JS scan = new JS();
int t = scan.nextInt();
while(t-->0){
int n = scan.nextInt();
long[] arr =new long[n];
for(int i = 0;i<n;i++){
arr[i] = scan.nextInt();
}
int count = 0;
for(int i = 0;i<n;i++){
int start = (int) ((arr[i]+(i+1) / arr[i] *arr[i]) - (i+1));
for(int j = start;j<=n;j+=arr[i]){
if(j-1<=i)continue;
long at = arr[j-1];
if(arr[i]*at==(i+1)+j){
//System.out.println((i+1) +" "+(j));
count++;
}
}
}
System.out.println(count);
}
}
static class JS {
public int BS = 1 << 16;
public char NC = (char) 0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public long nextLong() {
num = 1;
boolean neg = false;
if (c == NC) c = nextChar();
for (; (c < '0' || c > '9'); c = nextChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = nextChar()) {
res = (res << 3) + (res << 1) + c - '0';
num *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / num;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c > 32) {
res.append(c);
c = nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c != '\n') {
res.append(c);
c = nextChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = nextChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | cfd047da58cdfbc499a1fc702383d642 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class A728Best {
public static void main(String[] args) {
JS scan = new JS();
int t = scan.nextInt();
while (t-- > 0) {
int n = scan.nextInt();
element[] arr = new element[n];
for (int i = 0; i < n; i++) {
arr[i] = new element(scan.nextInt(), i + 1);
}
Arrays.sort(arr);
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
//System.out.println(arr[i].val*arr[j].val+" "+arr[i].idx+" "+arr[j].idx);
if (arr[i].val * arr[j].val > 2 * n) break;
if (arr[i].val * arr[j].val == arr[i].idx + arr[j].idx) {
count++;
}
}
}
System.out.println(count);
}
}
static class element implements Comparable<element> {
long val;
int idx;
public element(int val, int idx) {
this.val = val;
this.idx = idx;
}
@Override
public int compareTo(element o) {
return Long.compare(this.val,o.val);
}
}
static class JS {
public int BS = 1 << 16;
public char NC = (char) 0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public long nextLong() {
num = 1;
boolean neg = false;
if (c == NC) c = nextChar();
for (; (c < '0' || c > '9'); c = nextChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = nextChar()) {
res = (res << 3) + (res << 1) + c - '0';
num *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / num;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c > 32) {
res.append(c);
c = nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = nextChar();
while (c != '\n') {
res.append(c);
c = nextChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = nextChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 6e02387079c83f289b0499f974069d61 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
//System.out.println(n);
for (int i = 0; i < n; i++) {
int k = scan.nextInt();
int[] a = new int[k];
for (int ii = 0; ii < k; ii++) {
a[ii] = scan.nextInt();
}
System.out.println(new Finder(a).find());
}
}
public static class Pair implements Comparable<Pair> {
int index;
Integer value;
public Pair(int index, int value) {
this.index = index;
this.value = value;
}
@Override
public int compareTo(Pair i) {
return -Integer.compare(i.value, value);
}
}
public static class Finder {
int[] a;
public Finder(int[] a) {
this.a = a;
}
public int find() {
int out = 0;
List<Pair> list = new ArrayList<>(a.length);
for (int i = 0; i < a.length; i++) {
list.add(new Pair(i, a[i]));
}
Collections.sort(list);
for (int i = 0; i < a.length; i++) {
int cur = list.get(i).value;
int maxIndex = 2 * a.length /cur + 1;
if (maxIndex > a.length) {
maxIndex = a.length;
}
for(int ii = i + 1; ii < maxIndex; ii ++) {
if (list.get(i).index + list.get(ii).index + 2 == list.get(i).value * list.get(ii).value) {
out++;
}
}
}
return out;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 7020d51ebc931f5ac6b71fdc1ccb8b11 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
inputAndSettingData();
}
static int solve(int[] arr, int N) {
int cnt = 0;
for (int aiaj = 3; aiaj <= 2 * N; aiaj++) {
int sq = (int) Math.sqrt(aiaj);
for (int ai = 1; ai <= sq; ai++) {
if (aiaj % ai == 0 && aiaj != ai * ai && arr[ai] + arr[aiaj / ai] == aiaj) {
cnt++;
}
}
}
return cnt;
}
static void inputAndSettingData() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder out = new StringBuilder();
int T = Integer.parseInt(st.nextToken());
while (T-- > 0) {
int N = Integer.parseInt(br.readLine());
int SZ = 2 * N + 1;
int[] arr = new int[SZ];
Arrays.fill(arr, SZ);
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[Integer.parseInt(st.nextToken())] = i + 1;
}
out.append(solve(arr, N)).append("\n");
}
System.out.println(out);
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 9c38cc605c7bf7c38c0ee05cb8fad782 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
inputAndSettingData();
}
static int solve(int[] arr, int N) {
int cnt = 0;
for (int aiaj = 3; aiaj <= 2 * N; aiaj++) {
int sq = (int) Math.sqrt(aiaj);
for (int ai = 1; ai <= sq; ai++) {
if (aiaj % ai == 0 && aiaj != ai * ai && arr[ai] + arr[aiaj / ai] == aiaj) {
cnt++;
}
}
}
return cnt;
}
static void inputAndSettingData() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder out = new StringBuilder();
int T = Integer.parseInt(st.nextToken());
while (T-- > 0) {
int N = Integer.parseInt(br.readLine());
int[] arr = new int[2 * N + 1];
Arrays.fill(arr, (int) 1e6);
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[Integer.parseInt(st.nextToken())] = i + 1;
}
out.append(solve(arr, N)).append("\n");
}
System.out.println(out);
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0241a1b2cf13c2df9e8f1a7bc1c9fa43 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
inputAndSettingData();
}
static int solve(int[] arr, int N) {
int cnt = 0;
for (int i = 3; i <= 2 * N; i++) {
int sq = (int) Math.sqrt(i);
for (int j = 1; j <= sq; j++) {
if (i % j == 0 && i != j * j && arr[j] + arr[i / j] == i) {
cnt++;
}
}
}
return cnt;
}
static void inputAndSettingData() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder out = new StringBuilder();
int T = Integer.parseInt(st.nextToken());
while (T-- > 0) {
int N = Integer.parseInt(br.readLine());
int[] arr = new int[2 * N + 1];
Arrays.fill(arr, (int) 1e6);
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[Integer.parseInt(st.nextToken())] = i + 1;
}
out.append(solve(arr, N)).append("\n");
}
System.out.println(out);
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b945fd883ef321d9645f126c18f1cc34 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package codeforces;
import java.io.*;
import java.util.*;
public class ProblemB {
public static void main(String[] args) throws FileNotFoundException {
FastReader scanner = new FastReader(false);
int n = scanner.nextInt();
for (int i = 0; i < n; i++) {
solve(scanner);
}
}
public static void solve(FastReader scanner) {
long n = scanner.nextLong();
long[] arr = new long[(int) (n + 1)];
for (int i = 1; i <= n; i++) {
arr[i] = scanner.nextInt();
}
long count = 0;
for (long i = 1; i <= n; i++) {
for (long j = arr[(int) i] - i; j <= n; j += arr[(int) i]) {
if (j >= 0 && ((arr[(int) i] * arr[(int) j]) == (i) + (j)) && (i < j)) count++;
}
}
System.out.println(count);
}
static long upperBound(long[] arr, int start, int end, long k) {
int N = end;
while (start < end) {
int mid = start + (end - start) / 2;
if (k >= arr[mid]) {
start = mid + 1;
} else {
end = mid;
}
}
if (start < N && arr[start] <= k) {
start++;
}
return start;
}
static long lowerBound(long[] arr, int start, int end, long k) {
int N = end;
while (start < end) {
int mid = start + (end - start) / 2;
if (k <= arr[mid]) {
end = mid;
} else {
start = mid + 1;
}
}
if (start < N && arr[start] < k) {
start++;
}
return start;
}
static int getDistance(int x1, int y1, int x2, int y2) {
return Math.abs(x1 - x2) + Math.abs(y1 - y2);
}
static int sumOfNNaturalNumbers(int n) {
return (n * (n + 1)) / 2;
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader(boolean fromFile) throws FileNotFoundException {
if (!fromFile) {
br = new BufferedReader(
new InputStreamReader(System.in)
);
} else {
br = new BufferedReader(
new InputStreamReader(
new FileInputStream("src/main/java/codeforces/input.txt")
)
);
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | f02703998aca04bbc9e932fda98ef383 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class ProbB {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int cases = Integer.parseInt(bf.readLine());
for(int caseNum=0; caseNum<cases; caseNum++) {
int n = Integer.parseInt(bf.readLine());
int[] arr = new int[(2*n)+1];
Arrays.fill(arr, -1);
st = new StringTokenizer(bf.readLine());
for(int i=1; i<=n; i++)
arr[Integer.parseInt(st.nextToken())] = i;
int numPairs = 0;
for(int sum=3; sum<2*n; sum++) {
for(int i=1; i*i<=sum; i++) {
if(sum%i==0 && i*i!=sum && arr[i]!=-1 && arr[sum/i]!=-1 && arr[i]+arr[sum/i]==sum)
numPairs++;
}
}
System.out.println(numPairs);
}
bf.close();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b4c567a61c17578f81d6c2d23a6ab8ff | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
/* Name of the class has to be "Main" only if the class is public. */
public class hello
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
try {
br=new BufferedReader(new FileReader("input.txt"));
PrintStream out= new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
}
// Catch block to handle the exceptions
catch (Exception e) {
br=new BufferedReader(new InputStreamReader(System.in));
}
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) throws java.lang.Exception
{
try{
FastReader sc=new FastReader();
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(System.out));
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
long arr[]=new long[n+1];
for(int i=1;i<=n;i++){
arr[i]=sc.nextLong();
}
long count=0;
for(int i=1;i<=n;i++){
for(int j=(int)(arr[i]-i);j<=n;j+=arr[i]){
if(i<j&&arr[i]*arr[j]==i+j)
count++;
}
}
out.write(count+"\n");
out.flush();
}
}catch(Exception e){
return;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b8b349df8804c7b3f678e3f9ef23a32c | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import javafx.util.Pair;
public class Main
{
static void sort(long a[])
{
Random ran = new Random();
for (int i = 0; i < a.length; i++) {
int r = ran.nextInt(a.length);
long temp = a[r];
a[r] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
public static void main(String[] args)
{
FastScanner input = new FastScanner();
int tc = input.nextInt();
while (tc-- > 0) {
int n = input.nextInt();
long a[] = new long[n];
HashMap<Long,Integer> map = new HashMap<>();
for (int i = 0; i <n; i++) {
a[i] = input.nextLong();
map.put(a[i], i+1);
}
long ans = 0;
sort(a);
for (int i = 0; i < n; i++) {
for (int j =0; j < n; j++) {
if(i==j)
continue;
if(a[i]*a[j]>(2*n))
break;
if(a[i]*a[j]==(map.get(a[i])+map.get(a[j])))
{
ans++;
}
}
}
System.out.println(ans/2);
}
}
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) {
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() throws IOException
{
return br.readLine();
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c11635748043d7640a4d9378b50e6d60 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import javafx.util.Pair;
public class Main
{
public static void main(String[] args)
{
FastScanner input = new FastScanner();
int tc = input.nextInt();
while (tc-- > 0) {
int n = input.nextInt();
long a[] = new long[n+1];
for (int i = 1; i <=n; i++) {
a[i] = input.nextLong();
}
long count=0;
for (int i = 1; i <=n; i++) {
for (int j = (int)(a[i]-i); j <=n; j+=a[i]) {
if(j>=0)
{
if((a[i]*a[j]==i+j)&&(i<j))
count++;
}
}
}
System.out.println(count);
}
}
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) {
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() throws IOException
{
return br.readLine();
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 3de1801e0a7c5348f44822f6094b0247 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
while (t != 0) {
st = new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
List<Pair> list=new ArrayList<>();
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++){
list.add(new Pair(i,Integer.parseInt(st.nextToken())));
}
list.sort(Comparator.comparing(Pair::getY));
int count=0;
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
Pair one=list.get(i);
Pair two=list.get(j);
long prod= (long) one.getY() *two.getY();
long sum=one.getX()+two.getX()+2;
if(prod< 2L *n){
if(prod==sum){
count++;
}
}
else{
break;
}
}
}
sb.append(count).append("\n");
t--;
}
System.out.println(sb);
}
public static class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 360bcdb929b53fd9617157320658b82e | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = sc.nextInt();
long[] arr = new long[n + 1];
// read array
for (int i = 1; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
solveTask2(arr, n);
}
out.close();
}
private static void solveTask2(long[] arr, int n) {
int count = 0;
for (int i = 1; i <= n; i++) {
for (long j = arr[i] - i; j <= n; j += arr[i]) {
if (j >= 0) {
if (arr[i] * arr[(int) j] == i + j && i < j)
count++;
}
}
}
System.out.println(count);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] temparr = new int[n];
for (int i = 0; i < n; i++) {
temparr[i] = nextInt();
}
return temparr;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b3054b56abb67eec6e585c98a4fa3803 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package Codeforces;
import java.util.*;
import java.io.*;
public class PleasantPairs {
static FastReader in=new FastReader();
static final Random random=new Random();
static long mod=1000000007L;
//static HashMap<String,Integer>map=new HashMap<>();
public static void main(String args[]) throws IOException {
int t=in.nextInt();
int cse=1;
loop:
while(t-->0)
{
System.out.println(solve());
}
}
static long solve(){
int n=in.nextInt();
int nums[]=new int[2*n+1];
Arrays.fill(nums,-1);
for (int i = 0; i <n ; i++) {
int no=in.nextInt();
nums[no]=i+1;
}
long ans=0L;
for(long sum=3;sum<=2*n-1;sum++){
for(int f=1;f*f<sum;f++){
if(nums[f]!=-1 && sum%f==0){
int s=(int)sum/f;
if(nums[s]!=-1) {
if (nums[s] + nums[f] == sum) ans++;
}
}
}
}
return ans;
}
static int max(int a, int b)
{
if(a<b)
return b;
return a;
}
static void ruffleSort(int[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static < E > void print(E res)
{
System.out.println(res);
}
static int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static int abs(int a)
{
if(a<0)
return -1*a;
return a;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
int [] readintarray(int n) {
int res [] = new int [n];
for(int i = 0; i<n; i++)res[i] = nextInt();
return res;
}
long [] readlongarray(int n) {
long res [] = new long [n];
for(int i = 0; i<n; i++)res[i] = nextLong();
return res;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 671212fc72e04f26017a8004dd3c1cb5 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class PleasantPairs {
public static void solution() {
//TODO
}
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int tt = Integer.parseInt(reader.readLine()); // One number per line
for (int t = 0; t < tt; t++) {
int length = Integer.parseInt(reader.readLine());
StringTokenizer info = new StringTokenizer(reader.readLine()); // Multiple numbers per line
Long[] arr = new Long[length];
Map<Long, Integer> map = new HashMap<>();
for (int i = 0; i < length; i++) {
arr[i] = Long.parseLong(info.nextToken()); // For next number
map.put(arr[i], i + 1);
}
Arrays.sort(arr);
int ans = 0;
for (int i = 0; i < length; i++) {
for (int j = i + 1; j < length; j++) {
if (arr[i] * arr[j] > 2 * length) {
break;
}
else {
//System.out.println(arr[i] * arr[j] + " " + map.get(arr[i]) + " " + map.get(arr[j]));
if (arr[i] * arr[j] == map.get(arr[i]) + map.get(arr[j])) {
ans++;
}
}
}
}
writer.println(ans);
}
reader.close();
writer.close();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 8e7895ec4288804c1127fb124937f1d7 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class CodeforcesRound728 {
static FastReader sc = new FastReader();
public static void main(String[] args) throws IOException {
try {
int t = sc.nextInt();
while (t-- > 0) {
C();
}
} catch (Exception e) {
return;
}
}
static void C() {
int n = sc.nextInt();
long a[] = sc.readLongArray(n);
HashMap<Long,Integer> map = new HashMap<>();
for(int i=0;i<n;i++) {
map.put(a[i], i);
}
Arrays.sort(a);
long count = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
long c = a[i] * a[j];
long d = (map.get(a[i]) + 1) + (map.get(a[j]) + 1);
if (c == d)
count++;
if (c > 2 * n)
break;
}
}
System.out.println(count);
}
static void B() {
int n = sc.nextInt();
long a[] = sc.readLongArray(n);
long summ = 0, val = 0;
Arrays.sort(a);
for (int i = 2; i < n; i++) {
summ += a[i - 2];
val -= (a[i] * (i - 1));
val += summ;
}
System.out.println(val);
}
static void A() {
int n = sc.nextInt();
int a[] = new int[n];
if (n % 2 != 0) {
if (n == 3) {
System.out.println("3 1 2");
return;
} else {
System.out.print("3 1 2 ");
for (int i = 3; i < n; i++) {
a[i] = i + 1;
}
for (int i = 3; i < n - 1; i += 2) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
for (int i = 3; i < n; i++) {
System.out.print(a[i] + " ");
}
return;
}
} else {
for (int i = 0; i < n; i++) {
a[i] = i + 1;
}
for (int i = 0; i < n - 1; i += 2) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
for (int i : a) {
System.out.print(i + " ");
}
System.out.println();
}
static boolean[] seiveOfEratosthenes(int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
for (int i = 2; i * i <= n; i++) {
for (int j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
return isPrime;
}
static boolean isPrime(long n) {
if (n < 2)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(next());
}
return a;
}
void printIntArray(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
long[] readLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Long.parseLong(next());
}
return a;
}
void printLongArray(long a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 559ec767b31c4dd381bcf728387fc8f1 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class CodeforcesRound728 {
static FastReader sc = new FastReader();
public static void main(String[] args) throws IOException {
try {
int t = sc.nextInt();
while (t-- > 0) {
C();
}
} catch (Exception e) {
return;
}
}
static void C() {
int n = sc.nextInt();
int a[] = new int[n];
int ar[] = new int[2*n+1];
Arrays.fill(ar, (int)1e6);
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
ar[a[i]] = i+1;
}
int count = 0;
for (int i = 3; i < 2 * n; i++) {
for (int j = 1; j <= Math.sqrt(i); j++) {
if (i % j == 0 && i != j * j) {
if (ar[j] + ar[i / j] == i) {
count++;
}
}
}
}
System.out.println(count);
}
static void B() {
int n = sc.nextInt();
long a[] = sc.readLongArray(n);
long summ = 0, val = 0;
Arrays.sort(a);
for (int i = 2; i < n; i++) {
summ += a[i - 2];
val -= (a[i] * (i - 1));
val += summ;
}
System.out.println(val);
}
static void A() {
int n = sc.nextInt();
int a[] = new int[n];
if (n % 2 != 0) {
if (n == 3) {
System.out.println("3 1 2");
return;
} else {
System.out.print("3 1 2 ");
for (int i = 3; i < n; i++) {
a[i] = i + 1;
}
for (int i = 3; i < n - 1; i += 2) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
for (int i = 3; i < n; i++) {
System.out.print(a[i] + " ");
}
return;
}
} else {
for (int i = 0; i < n; i++) {
a[i] = i + 1;
}
for (int i = 0; i < n - 1; i += 2) {
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
for (int i : a) {
System.out.print(i + " ");
}
System.out.println();
}
static boolean[] seiveOfEratosthenes(int n) {
boolean[] isPrime = new boolean[n + 1];
Arrays.fill(isPrime, true);
for (int i = 2; i * i <= n; i++) {
for (int j = i * i; j <= n; j += i) {
isPrime[j] = false;
}
}
return isPrime;
}
static boolean isPrime(long n) {
if (n < 2)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(next());
}
return a;
}
void printIntArray(int a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
long[] readLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Long.parseLong(next());
}
return a;
}
void printLongArray(long a[]) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | df43384b76fde491555ab48dc63a081d | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class C {
private static void sport(int[] a) {
Map<Integer, Integer> map = new HashMap<>();
int n = a.length;
for (int i = 0; i < n; i++) {
map.put(a[i], i + 1);
}
int max = n + n - 1;
int ans = 0;
for (int i = 2; i <= max; i++) {
for (int j = 1; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
if ((i / j) == j) {
continue;
}
Integer integer1 = map.get(j);
Integer integer2 = map.get(i / j);
if (integer1 == null || integer2 == null) {
continue;
}
int val = integer1 + integer2;
if (val == i) {
ans++;
}
}
}
}
System.out.println(ans);
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
for (int p = 0; p < t; p++) {
int n = sc.nextInt();
int[] a = sc.readArrayInt(n);
sport(a);
}
}
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 nextInt() {
return Integer.parseInt(next());
}
long[] readArrayLong(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
int[] readArrayInt(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 88fe440b328164e9b6632e83ee4d6e70 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.math.*;
public class Solution
{
static StringBuilder sb;
static dsu dsu;
static long fact[];
static long mod=(long)(1e9+7);
static ArrayList<Integer>prime;
static int A[];
//static boolean visited[];
static ArrayList<Integer>adj[];
static void solve()
{
int n=i();
int A[]=new int[n+1];
int X[]=new int[2*n+1];
for(int i=1;i<=n;i++) {
A[i]=i();
X[A[i]]=i;
}
int cnt=0;
HashSet<Integer>hs=new HashSet<>();
for(int i=1;i<=n;i++)
{
int n1=A[i];
int f1=i;
int j=2;
while(n1*j<2*n)
{
int pre=n1*j;
if(pre-i<=n&&pre-i>=1&&pre-i!=i)
{
if(A[pre-i]==j)
{
pair p=new pair(Math.min(i, pre-i),Math.max(i, pre-i));
cnt++;
int val=p.x*100+p.y;
hs.add(val);
}
}
j++;
}
}
//System.out.println(cnt);
sb.append(hs.size()+"\n");
}
public static void main(String[] args)
{
sb=new StringBuilder();
int test=i();
for(int tt=1;tt<=test;tt++)
{
solve();
}
System.out.println(sb);
}
//*******************************************NCR%P*******************************************************
static long ncr(int n, int r)
{
if(r>n)
return (long)0;
long res=fact[n]%mod;
//System.out.println(res);
res=((long)(res%mod)*(long)(p(fact[r],mod-2)%mod))%mod;
res=((long)(res%mod)*(long)(p(fact[n-r],mod-2)%mod))%mod;
//System.out.println(res);
return res;
}
static long p(long x, long y)//POWER FXN //
{
if(y==0)
return 1;
long res=1;
while(y>0)
{
if(y%2==1)
{
res=(res*x)%mod;
y--;
}
x=(x*x)%mod;
y=y/2;
}
return res;
}
static long ceil(long num, long den)
{
return (long)(num+den-1)/den;
}
//*******************************************END*******************************************************
static int LowerBound(long a[], long x, int i, int j)
{
//X is the key value
int l=i;int r=j;
int lb=-1;
while(l<=r)
{
int m=(l+r)/2;
if(a[m]>=x)
{
lb=m;
r=m-1;
}
else l=m+1;
}
return lb;
}
static int UpperBound(long a[], long x, int i, int j)
{// x is the key or target value
int l=i,r=j;
int ans=-1;
while(l<=r)
{
int m=(l+r)/2;
if(a[m]<=x)
{
ans=m;
l=m+1;
}
else r=m-1;
}
return ans;
}
//*********************************Disjoint set union*************************//
static class dsu
{
int parent[];
dsu(int n)
{
parent=new int[n+1];
for(int i=0;i<=n;i++)
parent[i]=-1;
}
int find(int a)
{
if(parent[a]<0)
return a;
else
{
int x=find(parent[a]);
parent[a]=x;
return x;
}
}
void merge(int a,int b)
{
a=find(a);
b=find(b);
if(a==b)
return;
parent[b]=a;
}
}
//*******************************************PRIME FACTORIZE *****************************************************************************************************//
static TreeMap<Integer,Integer> prime(long n)
{
TreeMap<Integer,Integer>h=new TreeMap<>();
long num=n;
for(int i=2;i<=Math.sqrt(num);i++)
{
if(n%i==0)
{
int nt=0;
while(n%i==0) {
n=n/i;
nt++;
}
h.put(i, nt);
}
}
if(n!=1)
h.put((int)n, 1);
return h;
}
//*************CLASS PAIR ***********************************************************************************************************************************************
static class pair implements Comparable<pair>
{
int x;
int y;
pair(int x, int y)
{
this.x = x;
this.y = y;
}
public int compareTo(pair o)
{
return(int) (y-o.y);
}
}
//*************CLASS PAIR *****************************************************************************************************************************************************
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static InputReader in = new InputReader(System.in);
static OutputWriter out = new OutputWriter(System.out);
public static int[] sort(int[] a) {
int n = a.length;
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
return a;
}
public static long[] sort(long[] a) {
int n = a.length;
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a[i] = l.get(i);
return a;
}
public static long pow(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 != 0) {
res = (res * x);// % modulus;
y--;
}
x = (x * x);// % modulus;
y = y / 2;
}
return res;
}
//GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
//****************LOWEST COMMON MULTIPLE *************************************************************************************************************************************
public static long lcm(long x, long y) {
return (x * (y / gcd(x, y)));
}
//INPUT PATTERN******************************************************************************************************************************************************************
public static int i() {
return in.Int();
}
public static long l() {
String s = in.String();
return Long.parseLong(s);
}
public static String s() {
return in.String();
}
public static int[] readArray(int n) {
int A[] = new int[n];
for (int i = 0; i < n; i++) {
A[i] = i();
}
return A;
}
public static long[] readArray(long n) {
long A[] = new long[(int) n];
for (int i = 0; i < n; i++) {
A[i] = l();
}
return A;
}
public int[][] deepCopy(int[][] matrix) {
return java.util.Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone());
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b17199c327c94ed65bdbcb0d79f6dfeb | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
public static int Gcd(int a,int b){
if(b==0)return a;
return Gcd(b,a%b);
}
public static void main(String[] args){
Scanner scn=new Scanner(System.in);
int t=scn.nextInt();
while(t-->0){
int n=scn.nextInt();
int[] arr=new int[n+1];
for(int i=1;i<=n;i++){
arr[i]=scn.nextInt();
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=arr[i]-i;j<=n;j+=arr[i]){
if(j>i&&arr[i]*1l*arr[j]==(long)(i+j))cnt++;
}
}
System.out.println(cnt);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 3e80cf1e53bfc733e5552ff1f3e97e44 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class Solution {
// static boolean prime[] = new boolean[10000001];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
long arr[]=new long[n+1];
for (int i = 1; i < n+1; i++) {
arr[i]=sc.nextLong();
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j = (int) (arr[i]-i); j<=n; j+=arr[i])
{
if(j>=0) {
if ((i + j) == (arr[i] * arr[j]) && i<j) {
ans++;
}
}
//
}
}
System.out.println(ans);
}
}
// static void sieveOfEratosthenes(int n)
// {
//
//
// for(int i=0;i<=n;i++)
// prime[i] = true;
//
// for(int p = 2; p*p <=n; p++)
// {
// // If prime[p] is not changed, then it is a prime
// if(prime[p] == true)
// {
// // Update all multiples of p
// for(int i = p*p; i <= n; i += p)
// prime[i] = false;
// }
// }
//
// // Print all prime numbers
//// for(int i = 2; i <= n; i++)
//// {
//// if(prime[i] == true)
//// System.out.print(i + " ");
//// }
// }
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | fd375abeb003b6c53b2c70f0b0b345b1 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Omar {
static PrintWriter pw = new PrintWriter(System.out);
static Scanner sc=new Scanner(System.in);
public static ArrayList<pair> give(int n){
ArrayList<pair> arr=new ArrayList<>();
int end=(int)Math.sqrt(n);
for(int i=1;i<=end;i++) {
if(n%i==0) {
if(i*i==n);
else
arr.add(new pair(i, n/i));
}
}
return arr;
}
public static void main(String[] args) throws IOException {
ArrayList<pair>[] divisors=new ArrayList[200001];
for(int i=1;i<=200000;i++) {
divisors[i]=give(i);
}
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int []arr=new int[n+1];
HashMap<Long, Integer>hm=new HashMap<>();
for(int i=0;i<n;i++) {
int x=sc.nextInt();
hm.put(1l*x, i+1);
arr[i+1]=x;
}
long ans=0;
HashSet<pair>done=new HashSet<>();
for(int i=1;i<=2*n;i++) {
long sum=0;
ArrayList<pair> tmp=divisors[i];
for(int j=0;j<tmp.size();j++) {
if(!hm.containsKey(tmp.get(j).x) || !hm.containsKey(tmp.get(j).y))continue;
int a=hm.get(tmp.get(j).x),b=hm.get(tmp.get(j).y);
if(a+b==tmp.get(j).x*tmp.get(j).y) {
sum++;
}
}
ans+=sum;
}
pw.println(ans);
}
pw.flush();
}
static class SegmentTree {
long[] sTree, lazy;
int N;
public SegmentTree(int N) {
this.N = N;
sTree = new long[(N) << 1];
lazy = new long[(N) << 1];
}
public long query(int i, int j) {
return query(1, 1, N, i, j);
}
public long query(int node, int l, int r, int i, int j) {
if (i <= l && r <= j) {
return sTree[node];
}
if (r < i || l > j) {
return 0;
}
propagate(node, l, r);
int leftChild = node << 1;
int rightChild = node << 1 | 1;
int mid = l + r >> 1;
long leftQ = query(leftChild, l, mid, i, j);
long rightQ = query(rightChild, mid + 1, r, i, j);
return leftQ + rightQ;
}
public void propagate(int node, int l, int r) {
if (lazy[node] == 0) {
return;
}
int leftChild = node << 1;
int rightChild = node << 1 | 1;
int mid = l + r >> 1;
lazy[leftChild] += lazy[node];
lazy[rightChild] += lazy[node];
sTree[leftChild] += (mid - l + 1) * lazy[node];
sTree[rightChild] += (r - (mid + 1) + 1) * lazy[node];
lazy[node] = 0;
}
public void updateRange(int i, int j, long val) {
updateRange(1, 1, N, i, j, val);
}
public void updateRange(int node, int l, int r, int i, int j, long val) {
if (i <= l && r <= j) {
lazy[node] += val;
sTree[node] += (r - l + 1) * val;
return;
}
if (r < i || l > j) {
return;
}
propagate(node, l, r);
int leftChild = node << 1;
int rightChild = node << 1 | 1;
int mid = l + r >> 1;
updateRange(leftChild, l, mid, i, j, val);
updateRange(rightChild, mid + 1, r, i, j, val);
sTree[node] = sTree[leftChild] + sTree[rightChild];
}
}
static class pair implements Comparable<pair> {
long x;
long y;
public pair(long x, long y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair) o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Long(x).hashCode() * 31 + new Long(y).hashCode();
}
public int compareTo(pair other) {
if (this.x == other.x) {
return Long.compare(this.y, other.y);
}
return Long.compare(this.x, other.x);
}
}
static class tuble implements Comparable<tuble> {
int x;
int y;
int z;
public tuble(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return x + " " + y + " " + z;
}
public int compareTo(tuble other) {
if (this.x == other.x) {
if (this.y == other.y) {
return this.z - other.z;
}
return this.y - other.y;
} else {
return this.x - other.x;
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String file) throws IOException {
br = new BufferedReader(new FileReader(file));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String readAllLines(BufferedReader reader) throws IOException {
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
return content.toString();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextlongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public Long[] nextLongArray(int n) throws IOException {
Long[] a = new Long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 923298bc211c2d0bf4693f791c30ace6 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.Scanner;
public class PleasantPairs {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
while(num-->0){
int n = sc.nextInt();
int[] res = new int[n+1];
long count = 0;
for(int i = 1; i<=n; i++){
res[i] = sc.nextInt();
}
for(int i = 1; i<=n; i++){
for(int j = res[i] - i; j<=n; j += res[i]){
if(j >= 1 && (i+j == ((long) res[i] *res[j])) && i<j){
count++;
}
}
}
System.out.println(count);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 6981aa8188d43019913874bc9764750a | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class B728{
public static void main (String args[]) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int numTc = Integer.parseInt(br.readLine());
for(int tc = 0; tc <numTc; tc++) {
String input1 []= br.readLine().split(" ");
int n = Integer.parseInt(input1[0]);
int data []= new int [n+1];
String input2 []= br.readLine().split(" ");
for(int i=1; i <=n ; i++) {
data[i] = Integer.parseInt(input2[i-1]);
}
int total=0;
for(int i =1;i<=n;i++){
int j= i+1;
int wantedMod =( data[i] - i%data[i])%data[i];
int currentMod = j%data[i] ;
if(wantedMod!=currentMod){
j+= wantedMod>currentMod? wantedMod-currentMod : wantedMod+ data[i]-currentMod;
}
// while( j<=n && (j+i)%data[i]!=0)
// j++;
// data[i] - (data[i]-i%data[i]);
while(j<=n){
// System.out.println("i:"+i+" j:"+j+" data[i]: "+data[i]);
if((long)i+j==(long)data[i] * data[j])
total++;
j+=data[i];
}
}
System.out.println(total);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 12ea3b229125ea9f55de763947582712 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in).useLocale(Locale.US);
int t = sc.nextInt();
for(int i = 0; i<t; i++) {
System.out.println(solve(sc));
}
}
public static long solve(Scanner sc) {
int n = sc.nextInt();
long[] a = new long[n];
Map<Long, Integer> m = new HashMap<>();
for (int i = 0; i<n; i++) {
a[i] = sc.nextInt();
m.put(a[i], i+1);
}
long sum = 0;
for (int i = 1; i<=n; i++) {
long c = a[i-1];
for (long j = 1; j<= (2L *n)/c; j++) {
if (m.containsKey(j)) {
int idx = m.get(j);
if (idx != i && idx + i == j*c) {
sum += 1;
}
}
}
}
return sum/2;
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0099a3e4a7e9751623ab4f7466d000e5 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package CodeForces.RoadMap.diff1200;
import java.util.Scanner;
/**
* @author Syed Ali.
* @createdAt 08/07/2021, Thursday, 12:46
*/
public class PleasantPairs {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCases = scanner.nextInt();
for (int t = 0; t < testCases; t++) {
int n = scanner.nextInt();
long[] arr = new long[n + 1];
for (int i = 1; i <= n; i++) {
arr[i] = scanner.nextInt();
}
int answer = 0;
for (int i = 1; i <= n; i++) {
for (int j = (int) arr[i] - i; j <= n; j += arr[i]) {
if (j >= 0) {
if (arr[i] * arr[j] == i + j && i < j) {
++answer;
}
}
}
}
System.out.println(answer);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 9543b6c96b6956c9bf16d486e303d46b | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void solution(BufferedReader reader, PrintWriter writer)
throws IOException {
In in = new In(reader);
Out out = new Out(writer);
int T = in.nextInt();
for (int t = 0; t < T; t++) {
int n = in.nextInt();
int[] a = in.nextIntArray1(n);
int rst = 0;
for (int j = 2; j <= n; j++)
for (int i = a[j] - j % a[j]; i < j; i += a[j])
if (a[i] * a[j] == i + j)
rst++;
out.println(rst);
}
}
public static void main(String[] args) throws Exception {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(
new BufferedWriter(new OutputStreamWriter(System.out)));
solution(reader, writer);
writer.close();
}
protected static class In {
private BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("");
public In(BufferedReader reader) {
this.reader = reader;
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public int[] nextIntArray1(int n) throws IOException {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++)
a[i] = nextInt();
return a;
}
public int[] nextIntArraySorted(int n) throws IOException {
int[] a = nextIntArray(n);
Random r = new Random();
for (int i = 0; i < n; i++) {
int j = i + r.nextInt(n - i);
int t = a[i];
a[i] = a[j];
a[j] = t;
}
Arrays.sort(a);
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public long[] nextLongArray1(int n) throws IOException {
long[] a = new long[n + 1];
for (int i = 1; i <= n; i++)
a[i] = nextLong();
return a;
}
public long[] nextLongArraySorted(int n) throws IOException {
long[] a = nextLongArray(n);
Random r = new Random();
for (int i = 0; i < n; i++) {
int j = i + r.nextInt(n - i);
long t = a[i];
a[i] = a[j];
a[j] = t;
}
Arrays.sort(a);
return a;
}
}
protected static class Out {
private PrintWriter writer;
private static boolean local = System
.getProperty("ONLINE_JUDGE") == null;
public Out(PrintWriter writer) {
this.writer = writer;
}
public void print(char c) {
writer.print(c);
}
public void print(int a) {
writer.print(a);
}
public void printb(int a) {
writer.print(a);
writer.print(' ');
}
public void println(Object a) {
writer.println(a);
}
public void println(Object[] os) {
for (int i = 0; i < os.length; i++) {
writer.print(os[i]);
writer.print(' ');
}
writer.println();
}
public void println(int[] a) {
for (int i = 0; i < a.length; i++) {
writer.print(a[i]);
writer.print(' ');
}
writer.println();
}
public void println(long[] a) {
for (int i = 0; i < a.length; i++) {
writer.print(a[i]);
writer.print(' ');
}
writer.println();
}
public void flush() {
writer.flush();
}
public static void db(Object... objects) {
if (local)
System.out.println(Arrays.deepToString(objects));
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 84f2129ad73ae4997c525b256e8a9408 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.* ;
import java.io.* ;
@SuppressWarnings("unused")
public class cf
{
static final int mod = 1000000007 ;
static boolean not_prime[] = new boolean[1000001] ;
static void sieve() {
for(int i=2 ; i*i<1000001 ; i++) {
if(not_prime[i]==false) {
for(int j=2*i ; j<1000001 ; j+=i) {
not_prime[j]=true ;
}
}
}not_prime[0]=true ; not_prime[1]=true ;
}
public static long bexp(long base , long power)
{
long res=1L ;
//base = base%mod ;
while(power>0) {
if((power&1)==1) {
res=(res*base);//%mod ;
power-- ;
}
else {
base=(base*base);//%mod ;
power>>=1 ;
}
}
return res ;
}
static long modInverse(long n, long p)
{
return power(n, p - 2, p);
}
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more than or
// equal to p
x = x % p;
while (y > 0) {
// If y is odd, multiply x
// with result
if (y % 2 == 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static long nCrModPFermat(int n, int r, long p)
{
if(n<r) return 0 ;
if (r == 0)
return 1;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p
* modInverse(fac[n - r], p) % p)
% p;
}
private static long modular_add(long a, long b)
{
return ((a % mod) + (b % mod)) % mod;
}
private static long modular_sub(long a, long b)
{
return ((a % mod) - (b % mod) + mod) % mod;
}
private static long modular_mult(long a, long b)
{
return ((a % mod) * (b % mod)) % mod;
}
static long lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
private static long gcd(long a, long b)
{
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
static int cbits(int num) {
return (int)(Math.log(num) /Math.log(2)) + 1;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble(){ return Double.parseDouble(next()); };
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static HashMap<Integer , ArrayList<Integer>> map = new HashMap<>() ;
static boolean vis[] ;
static int parent[] , rank[] , points[] ;
public static void main(String[] args)throws IOException//throws FileNotFoundException
{
FastReader in = new FastReader() ;
StringBuilder op = new StringBuilder() ;
int t = in.nextInt();
while(t-->0)
{
int n = in.nextInt();
long a[] = new long[n+1] ;
for(int i=1 ; i<n+1 ; i++)a[i]=in.nextLong();
int res=0 ;
for(int i=1 ; i<n+1 ; i++)
{
for(int j=(int) (a[i]-i) ; j<n+1 ; j+=a[i])
{
if(j>i) {
if((a[i]*a[j])==(i+j))res++;
}
}
}
op.append(res+"\n");
}
System.out.println(op.toString());
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | bd87f67b3586bae1fa74c4372527c944 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.util.Scanner;
public class PleasantPairs {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testcases = Integer.parseInt(scanner.nextLine());
while(testcases-- != 0) {
int len = Integer.parseInt(scanner.nextLine());
int[] a = new int[len+1];
for(int i = 1; i <= len ; i++)
a[i] = Integer.parseInt(scanner.next());
scanner.nextLine();
int cnt = 0;
for(int i = 1 ; i <= len ; i++ ) {
for(int product = a[i] ; product <= 2*len ; product += a[i] ) {
int j = product - i;
if( i < j && j <= len && (long)a[i]*a[j]==i+j )cnt++;
}
}
System.out.println(cnt);
}
scanner.close();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | b7f07bb1fe25cae5823fec66bb2e86cd | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.util.Scanner;
public class PleasantPairs {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testcases = Integer.parseInt(scanner.nextLine());
while(testcases-- != 0) {
int len = Integer.parseInt(scanner.nextLine());
int[] a = new int[len];
for(int i = 0; i < len ; i++)
a[i] = Integer.parseInt(scanner.next());
scanner.nextLine();
int cnt = 0;
for(int i = 0 ; i < len ; i++ ) {
for(int product = a[i] ; product <= 2*len ; product += a[i] ) {
int j = product - i - 2;
if( i < j && j < len && (long)a[i]*a[j]==i+j+2 )cnt++;
}
}
System.out.println(cnt);
}
scanner.close();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 9d6dcec824ae78163cdb0490020ac254 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package Codeforces;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Solution {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
static Reader sc = new Reader();
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String args[]) throws IOException {
int t = inputInt();
while(t-->0){
int n =inputInt();
int[] a = new int[n+1];
for(int i=0;i<n;i++)a[i+1]=inputInt();
int count=0;
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=a[i]-(i%a[i]);j<=n;j+=a[i])
{
if(i>j && a[i]*a[j]==i+j)
cnt++;
}
}
System.out.println(cnt);
}
}
public static int inputInt() throws IOException {
return sc.nextInt();
}
public static long inputLong() throws IOException {
return sc.nextLong();
}
public static double inputDouble() throws IOException {
return sc.nextDouble();
}
public static String inputString() throws IOException {
return sc.readLine();
}
public static void print(String a) throws IOException {
bw.write(a);
}
public static void printSp(String a) throws IOException {
bw.write(a + " ");
}
public static void println(String a) throws IOException {
bw.write(a + "\n");
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 5833faa7fa2a74f45ed4ef93240c6b25 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Trials1
{
public static void main(String[] args) throws NumberFormatException, IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(inp.readLine());
while(t-- >0)
{
int n=Integer.parseInt(inp.readLine());
String s[]=inp.readLine().split(" ");
int a[]=new int[n+1];
for(int i=0;i<n;i++)
{
a[i+1]=Integer.parseInt(s[i]);
}
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=a[i]-(i%a[i]);j<=n;j+=a[i])
{
if(i>j && a[i]*a[j]==i+j)
cnt++;
}
}
out.write(Integer.toString(cnt)+"\n");
}
out.flush();
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 33039f19bd2d8b9ba29afa1facdeb69a | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.Scanner;
public class PleasantPairs {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
int test = a.nextInt();
for (int b = 0 ; b < test ; b++){
int n = a.nextInt() ;
int[] array = new int[n];
for (int c=0 ; c < n ; c++ )
array[c] = a.nextInt();
int sum = 0 ;
for (int c = 0 ; c < n ; c++ )
for (int d = ((-c - 2)%array[c] +array[c])%array[c] ; d < n ; d+=array[c] )
if ( c < d && array[d] == (d + c + 2)/array[c])sum++;
System.out.println(sum);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | db7afe91544062f25eae9edc55279fdb | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | /*==========================================================================
* AUTHOR: RonWonWon
* CREATED: 27.06.2021 22:50:16
/*==========================================================================*/
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
/*
in.ini();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
*/
long startTime = System.nanoTime();
int t = in.nextInt(), T = 1;
while(t-->0) {
int n = in.nextInt();
long a[] = in.readArrayL(n);
int cnt = 0;
for(int i=1;i<=n;i++){
for(int j=1;(a[i-1]*j-i)<=n;j++){
int y = (int)(a[i-1]*j-i);
if(y<=i) continue;
if(a[y-1]==j) cnt++;
}
}
out.println(cnt);
//out.println("Case #"+T+": "+ans); T++;
}
/*
startTime = System.nanoTime() - startTime;
System.err.println("Time: "+(startTime/1000000));
*/
out.flush();
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static int oo = Integer.MAX_VALUE;
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
void ini() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readArrayL(int n) {
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextLong();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readArrayD(int n) {
double a[] = new double[n];
for(int i=0;i<n;i++) a[i] = nextDouble();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSortL(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);
long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | abaee40852f7b7677b2da756fdcdb378 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class week4 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0) {
int n = s.nextInt();
long[] arr = new long[n];
Map<Long, Long> map = new HashMap<Long, Long>();
for (int i = 0; i < arr.length; i++) {
arr[i] = s.nextLong();
map.put(arr[i], (long)i+1);
}
long ans = 0;
Arrays.sort(arr);
for (int i = 0; i < n-1; i++) {
long x = map.get(arr[i]);
for (int j = i+1; j < n; j++) {
long y = map.get(arr[j]);
if(x+y == arr[i]*arr[j])ans++;
if(arr[i]*arr[j]>=2*n)
break;
}
}
System.out.println(ans);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0db4e16ecfdb1036e9e0694c8a9a6459 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package com.cf.div2.c728;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class B {
static PrintWriter out = new PrintWriter(System.out);
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) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
Map<Integer, Integer> map = new HashMap<>();
for (int i = 1; i <= n; i++) {
map.put(sc.nextInt(), i);
}
int ans = 0;
for (int i = 3; i < 2*n; i++) {
for (int j = 1; j*j < i; j++) {
if (i % j == 0) {
if (map.containsKey(j) && map.containsKey(i / j)) {
ans += map.get(j) + map.get(i / j) == i ? 1 : 0;
}
}
}
}
out.println(ans);
}
out.close();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | e813fa875601c77dcfd06ea4daa2e6d4 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | //package com.cf.div2.c728;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class B {
static PrintWriter out = new PrintWriter(System.out);
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) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
Map<Integer, Integer> map = new HashMap<>();
for (int i = 1; i <= n; i++) {
map.put(sc.nextInt(), i);
}
int ans = 0;
for (int i = 3; i < 2*n; i++) {
for (int j = 1; j < Math.sqrt(i); j++) {
if (i % j == 0) {
if (map.containsKey(j) && map.containsKey(i / j)) {
ans += map.get(j) + map.get(i / j) == i ? 1 : 0;
}
}
}
}
out.println(ans);
}
out.close();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 0e7d73f0bcff6803fa8abc2265cd3f39 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main7 {
public static void main(String[] args) {
FastScanner sc=new FastScanner();
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
long arr[]=new long[n+1];
for(int i=1;i<n+1;i++)
arr[i]=sc.nextInt();
int count=0;
for(int i=1;i<=n;i++) {
for(int j=(int)arr[i]-i;j<=n;j+=arr[i]) {
if(j>=0)
if(arr[i]*arr[j]==i+j&&i<j)
count++;
}
}
System.out.println(count);
}
}
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 nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | cbdba4fadd32904e0df9aa816a2833fc | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
public class CodeForces1541A{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for(int tt = 0;tt<t;tt++){
int n = input.nextInt();
int[] a = new int[n+1];
for(int i = 1;i<=n;i++){
a[i] = input.nextInt();
}
int count = 0;
for(int i = 1;i<=n;i++){
int remain = i % a[i];
int start = i - 2 * remain + a[i];
if(start >= i){
start -= a[i];
}
for(int j = start; j > 0; j -= a[i]){
if(j < i && i + j == a[i] * a[j]){
count++;
}
}
}
System.out.println(count);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | a3e8281ec048a2f56977d9ab2fabe06b | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws java.lang.Exception{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T-->0) {
int n=sc.nextInt();
int a[]=new int[n+1];
for(int i=1;i<=n;i++) {
a[i]=sc.nextInt();
}
long c=0;
for(int i=1;i<=n;i++) {
for(int j=a[i]-i;j<=n;j+=a[i]) {
if(j>=1)
if(((long)a[i]*a[j]==i+j)&&(i<j))
c++;
}
}
System.out.println(c);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | c166312c0c3ee78757f334ce1fb93fa2 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Solution implements Runnable
{
public static void solve()
{
int t = i();
while(t-->0){
int n = i();
int[] arr = new int[n+1];
TreeSet<Integer> hs = new TreeSet();
for(int i=1;i<=n;i++){
arr[i] = i();
hs.add(arr[i]);
}
int count =0;
for(int i=1;i<=n;i++){
for(int x: hs){
int y = x * arr[i] - i ;
if((y<=n && y>i) && arr[y] ==x){
count++;
}
if(y>n)break;
}
}
System.out.println(count);
}
}
public static boolean isVowel(char c)
{
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')return true;
return false;
}
public static int upperbound(int[] a,int low,int high,int key)
{
while(low<high)
{
int mid=(low+high)>>1;
if(a[mid]>key)
{
high=mid;
}
else
{
low=mid+1;
}
}
return low;
}
public static int lowerbound(int[] a,int low,int high,int key)
{
while(low<high)
{
int mid=(low+high)>>1;
if(a[mid]>=key)
{
high=mid;
}
else
{
low=mid+1;
}
}
return low;
}
public void run()
{
solve();
out.close();
}
public static void main(String[] args) throws IOException
{
new Thread(null, new Solution(), "whatever", 1<<26).start();
}
static class Pair implements Comparable<Pair>
{
long a;
int b;
Pair(){}
Pair(long a,int b)
{
this.a=a;
this.b=b;
}
public int compareTo(Pair x)
{
return Long.compare(x.a,this.a);
}
}
////////////////////////////////////////////////////// Merge Sort ////////////////////////////////////////////////////////////////////////
static class Merge
{
public static void sort(long inputArr[])
{
int length = inputArr.length;
doMergeSort(inputArr,0, length - 1);
}
private static void doMergeSort(long[] arr,int lowerIndex, int higherIndex)
{
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
doMergeSort(arr,lowerIndex, middle);
doMergeSort(arr,middle + 1, higherIndex);
mergeParts(arr,lowerIndex, middle, higherIndex);
}
}
private static void mergeParts(long[]array,int lowerIndex, int middle, int higherIndex)
{
long[] temp=new long[higherIndex-lowerIndex+1];
for (int i = lowerIndex; i <= higherIndex; i++)
{
temp[i-lowerIndex] = array[i];
}
int i = lowerIndex;
int j = middle + 1;
int k = lowerIndex;
while (i <= middle && j <= higherIndex)
{
if (temp[i-lowerIndex] < temp[j-lowerIndex])
{
array[k] = temp[i-lowerIndex];
i++;
} else {
array[k] = temp[j-lowerIndex];
j++;
}
k++;
}
while (i <= middle)
{
array[k] = temp[i-lowerIndex];
k++;
i++;
}
while(j<=higherIndex)
{
array[k]=temp[j-lowerIndex];
k++;
j++;
}
}
}
/////////////////////////////////////////////////////////// Methods ////////////////////////////////////////////////////////////////////////
static boolean isPal(String s)
{
for(int i=0, j=s.length()-1;i<=j;i++,j--)
{
if(s.charAt(i)!=s.charAt(j)) return false;
}
return true;
}
static String rev(String s)
{
StringBuilder sb=new StringBuilder(s);
sb.reverse();
return sb.toString();
}
static int gcd(int a,int b){return (a==0)?b:gcd(b%a,a);}
static long gcdExtended(long a,long b,long[] x)
{
if(a==0){
x[0]=0;
x[1]=1;
return b;
}
long[] y=new long[2];
long gcd=gcdExtended(b%a, a, y);
x[0]=y[1]-(b/a)*y[0];
x[1]=y[0];
return gcd;
}
boolean findSum(int set[], int n, long sum)
{
if (sum == 0)
return true;
if (n == 0 && sum != 0)
return false;
if (set[n-1] > sum)
return findSum(set, n-1, sum);
return findSum(set, n-1, sum) ||findSum(set, n-1, sum-set[n-1]);
}
public static long modPow(long base, long exp, long mod)
{
base = base % mod;
long result = 1;
while (exp > 0)
{
if (exp % 2 == 1)
{
result = (result * base) % mod;
}
base = (base * base) % mod;
exp = exp >> 1;
}
return result;
}
static long[] fac;
static long[] inv;
static long mod=(long)1e9+7;
public static void cal()
{
fac = new long[1000005];
inv = new long[1000005];
fac[0] = 1;
inv[0] = 1;
for (int i = 1; i <= 1000000; i++)
{
fac[i] = (fac[i - 1] * i) % mod;
inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;
}
}
public static long ncr(int n, int r)
{
return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
////////////////////////////////////////// Input Reader ////////////////////////////////////////////////////////////////////////////////////////////////////
static InputReader sc = new InputReader(System.in);
static PrintWriter out= new PrintWriter(System.out);
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext()
{
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n)
{
int a[] = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n)
{
long a[] = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = nextLong();
}
return a;
}
public String nextLine()
{
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c)
{
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
static int i()
{
return sc.nextInt();
}
static long l(){
return sc.nextLong();
}
static int[] iarr(int n)
{
return sc.nextIntArray(n);
}
static long[] larr(int n)
{
return sc.nextLongArray(n);
}
static String s(){
return sc.nextLine();
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 5b84570d7910f30f6f031defa2fb4ea0 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class PleasantPairs {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
static StringBuilder sb;
public void solve(int testNumber, InputReader in, PrintWriter out) {
//solution
int t = 1;
t = in.nextInt();
while (t-- > 0) {
function(in,out);
}
}
static void function(InputReader in,PrintWriter out){
int n = in.nextInt();
int[] arr = new int[n + 1];
for (int i = 1; i <= n; i++) {
arr[i] = in.nextInt();
}
long ans = 0L;
for (int i = 1; i <= n; i++) {
int skip = arr[i];
int st = skip - i;
int moves = 1;
while (st <= n) {
if (st > i && arr[st] == moves) {
ans++;
}
st += skip;
moves++;
}
}
out.println(ans);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | a1c7e58481668056bc68330e93d34424 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public final class Solution
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int k=Integer.parseInt(br.readLine());
while(k-- >0){
int n=Integer.parseInt(br.readLine());
int[] arr= new int[n];
String[]a= br.readLine().split(" ");
Map<Integer,Integer> res= new HashMap<>();
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(a[i]);
res.put(arr[i],i+1);
}
int count=0;
for(int i=3;i<2*n;i++){
count+=check(res,i,n);
}
System.out.println(count);
}
}
public static int check(Map<Integer,Integer> res,int a,int n){
int count=0;
for(int i=1;i*i<=a;i++){
if(a%i==0 &&i*i!=a&& res.containsKey(i)&&res.containsKey(a/i)&&res.get(i)+res.get(a/i)==a)count++;
}
return count;
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | 63eaf9aea2c991e80b4cc2957124bcbd | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class pleasantpairs {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(f.readLine());
long t = Long.parseLong(st.nextToken());
while(t > 0) {
t --;
long n = Long.parseLong(f.readLine());
st = new StringTokenizer(f.readLine());
long[] arr = new long[(int) n + 2];
for(int i = 1; i <= n; i ++) arr[i] = Long.parseLong(st.nextToken());
int count = 0;
for(int i = 1; i < n; i ++) {
long startingIndex = arr[i] - (i) % arr[i];
while(startingIndex <= i) startingIndex += arr[i];
for(int j = (int) startingIndex; j <= n; j += arr[i]) {
if(i < j && (long) arr[i] * (long) arr[j] == i + j) count ++;
}
}
System.out.println(count);
}
}
}
| Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output | |
PASSED | d5b70f21037720be1dc0d3af6d898007 | train_107.jsonl | 1624635300 | You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class pleasantPairs {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
int out = 0;
for(int i=0;i<n;i++){
int val = a[i];
int temp = val;
while(temp<=(i+1)){
temp += val;
}
int j = temp-(i+1);
while(j<=n){
if(a[j-1]==((i+1)+j)/val && i!=(j-1)){
// System.out.println(i+" "+(j-1));
out++;
}
temp +=val;
j=temp-(i+1);
}
}
System.out.println(out/2);
}
}
} | Java | ["3\n2\n3 1\n3\n6 1 5\n5\n3 1 5 9 2"] | 2 seconds | ["1\n1\n3"] | NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$. | Java 8 | standard input | [
"brute force",
"implementation",
"math",
"number theory"
] | 0ce05499cd28f0825580ff48dae9e7a9 | The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. | 1,200 | For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.