Chef and Weird Queries CodeChef Solution

Problem -Chef and Weird Queries CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

Chef and Weird Queries CodeChef Solution in C++17

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	// your code goes here
	ll int t;
	cin>>t;
	while(t--)
	{
	    ll int n,diff,ans=0;
	    cin>>n;
	    ll int near=floor(sqrt(n));
	    if(n>700){
	    ll int m=n-700;
	    ll int far=floor(sqrt(m));
	    ans=far*700;
	    for(int i=far+1;i<=near;i++){
	        int k=pow(i,2);
	       // cout<<k<<"~";
	        diff=(n-pow(i,2));
	            ans+=diff;
	    }
	    cout<<ans<<endl;
	    continue;
	    }
	    for(int i=1;i<=near;i++){
	        int k=pow(i,2);
	       // cout<<k<<"~";
	        diff=(n-pow(i,2));
	        if(diff>700){
	            ans+=700;
	        }
	        else{
	            ans+=diff;
	        }
	    }
	    cout<<ans<<endl;
	}
	return 0;
}

Chef and Weird Queries CodeChef Solution in C++14

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=1e7+1;
const ll mod=1e9+7;
#define F(i,a,b) for(i=a;i<b;i++)
#define FX(i,a,b,k) for(i=a;i<=b;i+=k)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define I(x) cin>>x;
#define OUT(x) cout<<x;
#define BL() cout<<"\n";
#define SP() cout<<" ";
#define sortA(x,n) sort(x,x+n);
#define sortV(x) sort(x.begin(),x.end())
#define revA(x,n) reverse(x,x+n);
#define revV(x) reverse(x.begin(),x.end())
#define LBA(v,n,x) lower_bound(v,v+n,x)-v;
#define UBA(v,n,x) upper_bound(v,v+n,x)-v;
#define LBV(v,x) lower_bound(v.begin(),v.end(),x)-v.begin();
#define UBV(v,x) upper_bound(v.begin(),v.end(),x)-v.begin();
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif  
	ll t,i,y;
	cin>>t;
	//t=1;
	while(t--){
	   cin>>y;
	   ll ans=0;
	   F(i,1,701){
	   	ll z=y-i;
	   	if(z>0){
	   		ll k=sqrt(z);
	   		ans+=k;
	   	}
	   }
	   cout<<ans<<"\n";
	}
}

Chef and Weird Queries CodeChef Solution in PYTH 3

for _ in range(int(input())):
    y = int(input())
    count=0
    a=int(pow(y,0.5))
    while a>0 and a*a>=y-700:
        count+=y-a*a
        a-=1
    print(a*700+count)

Chef and Weird Queries CodeChef Solution in C

#include <stdio.h>

int main(void) {
    int t;
    scanf("%d", &t);
    while(t--)
    {
        long long y;
        scanf("%lld", &y);
        long long sum = 0;
        for(long long i=1; i<=700; i++)
        {
            if(y-i>0)
                sum = sum + sqrt(y-i);
            else
                break;
        }
        printf("%lld\n", sum);
    }
	// your code goes here
	return 0;
}

Chef and Weird Queries CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

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
{
    static int mod = 1000000007;
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		
		Scanner sc = new Scanner(System.in);
		
		int t = sc.nextInt();
		
		while(t-->0){
		    
		    long ans = 0;
		    long y = sc.nextLong();
		    for(int i=1;i<=700&&(y-i)>=0;i++){
		        
		        ans += Math.sqrt(y-i);
		        
		    }
		    
		    System.out.println(ans);
		}
		
		
		
	}
}

Chef and Weird Queries CodeChef Solution in PYPY 3

import math
testcases = int(input())
for eachcase in range(testcases):
    limit = int(input())
    
    count = 0
    rootvar = int(math.ceil(math.sqrt(limit)) - 1)
    if limit - (rootvar ** 2) > 700:
        count += rootvar * 700
    else:
        while rootvar != 0:
            curr = limit - (rootvar ** 2)
            if curr > 700:
                break
            else:
                count += curr
            rootvar -= 1
        count += rootvar * 700
    
    print(count)

Chef and Weird Queries CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	Y = int(raw_input())
	if Y > 700:
		A = int((Y-700)**0.5)
		r = 700*A
	else:
		A = 0
		r = 0
	# endif
	A += 1
	A2 = A*A
	while A2 < Y:
		r += Y-A2
		A += 1
		A2 = A*A
	# endwhile
	print r
# endfor i

Chef and Weird Queries CodeChef Solution in C#

using System;

public class Test
{
            private interface IInputReader
        {
	        string ReadInput();
        }

        private class ConsoleReader : IInputReader
        {
	        public string ReadInput() => Console.ReadLine().Trim();
        }
    
	public static void Main()
	{
		checked
			{
				//var reader = new DebugReader();
				var reader = new ConsoleReader();
				var tests = int.Parse(reader.ReadInput());

				for (int test = 0; test < tests; test++)
				{
					var y = long.Parse(reader.ReadInput());
					long res = 0;
					for (long b = 1; b <= 700; b++)
					{
						var rem = y - b;
						if (rem >= 0)
						{
							var max = (long)Math.Floor(Math.Sqrt(rem));
							res += max;
						}
					}

					Console.WriteLine(res);
				}
			}
	}
}

Chef and Weird Queries CodeChef Solution in GO

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int

	fmt.Scanf("%d", &t)

	for t > 0 {
		var Y int64

		fmt.Scanf("%d", &Y)

		fmt.Println(solve(Y))

		t--
	}
}

func solve(Y int64) int64 {
	var ans int64
	for B := int64(1); B <= 700 && B < Y; B++ {
		X := float64(Y - B)
		A := int64(math.Sqrt(X))
		ans += A
	}

	return ans
}
Chef and Weird Queries CodeChef Solution Review:

In our experience, we suggest you solve this Chef and Weird Queries CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Chef and Weird Queries CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Chef and Weird Queries CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *