Fit Squares in Triangle Codechef Solution

Hello Programmers In this post, you will know how to solve the Fit Squares in Triangle Codechef Solution.

Fit Squares in Triangle Codechef Solution
Fit Squares in Triangle Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Chef has three socks in his drawer. Each sock has one of 10 possible colours, which are represented by integers between 1 and 10. Specifically, the colours of the socks are AB, and C. Chef has to wear two socks which have the same colour. Help Chef find out if that is possible or not.

Input

The first and only line of the input contains three space-separated integers AB and C.

Output

Print a single line containing the string “YES” if it is possible for Chef to wear two socks with the same colour or “NO” if it is impossible (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1 <= A, B, C <= 10

Subtasks

Subtask #1 (100 points): Original Constraints 

Example Input 1

5 4 3

Example Output 1

NO

Explanation

Since there are no two socks with the same colour, Chef cannot wear a pair of socks with the same colour.

Example Input 2

5 5 5

Example Output 2 

YES

Explanation 

Since all three socks have the same colour, Chef can wear a pair of socks with the same colour.

Fit Squares in Triangle CodeChef Solutions in Python

for _ in range(int(input())):
    n = int(input())
    n = n - 2
    n = n // 2
    print(int(n*(n+1)/2))

Fit Squares in Triangle CodeChef Solutions in CPP

#include <iostream>
using namespace std;
int num(int n){
    if(n<4) return 0;
    return (n-2)/2 + num(n-2);
}
int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        cout<<num(n)<<endl;
    }
    return 0;
}

Fit Squares in Triangle CodeChef Solutions in JAVA

import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc=new Scanner(System.in);
       int Test= sc.nextInt();
       while (Test-->0)
       {
           long base= sc.nextInt();
           base=base-2;
           base=Math.floorDiv(base,2);
           System.out.println(base*(base+1)/2);
       }
    }
}
Ezoicreport this ad

Disclaimer: The above Problem (Fit Squares in Triangle) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Valid Pair Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad