Advertisement
Guest User

vongtay6/4/2020

a guest
Apr 6th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package BaiToanTamHau;
  2. import java.util.Scanner ;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. public class Whitevalentine
  6. {
  7.     public static int []A = new int[100];
  8.     public static int []B = new int[100];
  9.     public static int n, tempt, th;
  10.     public static boolean snt (int a )
  11.     {
  12.         int count =0;
  13.         for(int i=2; i<= a/2; i++)
  14.         {
  15.             int k = a%i;
  16.             if( k== 0) count ++;
  17.         }
  18.         if( count != 0) return false;
  19.         else return true ;
  20.     }
  21.    public static void Try(int i)
  22.      {
  23.        B[i]= 1;
  24.        tempt ++;
  25.        for( int t= 0; t< n ; t++)
  26.        {
  27.            if(B[t]== 0 && snt(A[i]+A[t]))
  28.            {
  29.                if(tempt == n-1 && snt(A[0]+A[t]))
  30.                {
  31.                    th++;
  32.                }
  33.                else
  34.                {
  35.                    Try(t);
  36.                }
  37.            }
  38.        }
  39.  
  40.        tempt --;
  41.        B[i]=0;
  42.        
  43.    }
  44.     public static void main(String[] args) throws FileNotFoundException
  45.     {
  46.         System.setIn(new FileInputStream ("C:\\Users\\Thien\\Desktop\\file run\\vongtay.txt"));
  47.         Scanner mk = new Scanner( System.in);
  48.         int test = mk.nextInt();
  49.         for(int t=0 ;t<test ;t++)
  50.         {
  51.             n = mk.nextInt();
  52.             for( int i=0 ;i<n; i++)
  53.             {
  54.                 A[i]= mk.nextInt();
  55.             }
  56.             tempt = th =0;
  57.             Try(0);
  58.             System.out.print(th + "\n");
  59.         }
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement