CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Neliöt
Sender:TapaniS
Submission time:2020-11-07 08:57:46 +0200
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED72
Test results
testverdicttimegroup
#1ACCEPTED0.15 s1, 2details
#2ACCEPTED0.15 s1, 2details
#3ACCEPTED0.17 s2details

Code

import java.util.*;


public class neliot {


public static int find(int[] a, int target)
{
	for (int i = 0; i < a.length; i++)
		if (a[i] == target)
			return i;

	return -1;
}


	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();
		String[] ans = new String[t];
		int a = 0;
		int b = 0;
		int a2 = 0;
		int b2 = 0;

		for (int t1 = 0; t1 < t; t1++) {

			int n = input.nextInt();

			ans[t1] = "NO";

			if (n < 3) {
				ans[t1] = "YES";
				continue;
			}

		// n >= 3

			int maxVal1 = (int) Math.sqrt(n/2);
			int maxVal2 = (int) Math.sqrt(n);

			for (int i = maxVal2; i >= maxVal1; i--) {

				b2 = i * i;
				a = (int) Math.sqrt(n-b2);
				a2 = a * a;

				if ((a2 + b2) == n) {
					ans[t1] = "YES";
					break;
				}

			}

		}  // t1


		for (int i = 0; i < t; i++) {
			System.out.println(ans[i]);
		}

		input.close(); 
    }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
100
1
2
3
4
...

correct output
YES
YES
NO
YES
YES
...

user output
YES
YES
NO
YES
YES
...

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
100
522
419
402
969
...

correct output
YES
NO
NO
NO
NO
...

user output
YES
NO
NO
NO
NO
...

Test 3

Group: 2

Verdict: ACCEPTED

input
100
575833539
744851460
436154655
655319365
...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...