triplet bội 5

 avatar
user_1741892783
c_cpp
2 years ago
1.5 kB
3
Indexable
Never
//package com.company;

import java.util.*;

public class Main {
    static boolean findPair(List<Integer> list, int k){

        Set<Integer> set = new HashSet<>();
        for(int a: list){
            set.add(a);
        }
        int sum = k;
        for(int a:list){
            if(set.contains(sum - a))
            {
                return true;
            }
        }
        return false;
    }
    static int findTriplet(List<Integer> list, int k, int count){
        int sum = k;
        for(int a: list){
            if(findPair(list, sum - a)){
                count++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        int count =0;
        int n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
//            System.out.printf("a[%d] = ", i);
            arr[i] = sc.nextInt();
        }
        //List<Integer> list = (List<Integer>) Arrays.asList(arr);
        List<Integer> list2 = new ArrayList<Integer>();
        for(int id:arr) {
            list2.add(id);
        }
//        System.out.println(findPair(list2, 5));
//        System.out.println("\nend\n");
        for(int i  = 1; i < 1000; i = i * 5) {

            count += (findTriplet(list2, i, count));
        }
        System.out.println(count);
        //List<Integer> list = new ArrayList<Integer>();

    }
}