Instruction
stringlengths 261
35k
| Response
stringclasses 1
value |
---|---|
For this Question: You are given a positive integer N. Print the square of N.The input consists of a single integer N.
<b> Constraints: </b>
1 ≤ N ≤ 50Print a single integer β the value of N<sup>2</sup>.Sample Input 1:
5
Sample Output 1:
25, I have written this Solution Code: n=int(input())
print(n*n), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton's garden has N apple trees. Initially, there are A<sub>i</sub> apples attached to the ith tree. Also, there are M apples which newton has to attach to these tress for testing gravity laws.
In one minute, at most B<sub>i</sub> apples fall from the ith tree.
Help newton find the minimum time he has to wait after which he can safely sit under any apple tree.The first line contains two space-separated integers β N and M indicating the number of apple trees and the number of apples to be attached.
Each of the next N lines contains two integers A<sub>i</sub> and B<sub>i</sub> specifying the initial count of apples and rate of fall of apples per minute for ith tree.
<b> Constraints: </b>
1 <= N <= 2*10<sup>5</sup>
0 <= A<sub>i</sub> <= 10<sup>6</sup>
1 <= M, B<sub>i</sub> <= 10<sup>6</sup>Output minimum time Newton has to waitInput:
3 6
4 3
7 4
1 5
Output:
2
Explanation:
Attach 2, 1, 3 apples to 1st, 2nd, 3rd tree respectively. Then, 2, 2, 1 minutes are required for all apples to fall from 1st, 2nd, 3rd tree respectively. So, Wait time is max(2, 2, 1) = 2., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N = 2*1e5+5;
ll n,m;
vector<ll> a(N),b(N);
bool possible(ll time) {
ll lim = 0;
for(int i=0 ; i<n ; i++) lim += b[i] * time;
ll tot = m;
for(int i=0 ; i<n ; i++) tot += a[i];
if (tot > lim) return false;
for(int i=0 ; i<n ; i++) if (a[i] > b[i]*time) return false;
return true;
}
int main(){
cin >> n >> m;
for(int i=0 ; i<n ; i++){
cin >> a[i] >> b[i];
}
ll lo = 1, hi = 2*1e6+1000;
while(hi - lo > 1) {
ll mid = (hi+lo)/2;
if (possible(mid)){
hi = mid;
}else{
lo = mid;
}
}
cout << hi << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, reverse each word in the sentenceA string containing multiple words
ex:- "Welcome to this Javascript Guide!"A string with all words reversed
ex:- "emocleW ot siht tpircsavaJ !ediuG"Sample input:-
"Welcome to this Javascript Guide!"
Sample output:-
"emocleW ot siht tpircsavaJ !ediuG"
Explanation:-
The first word is reversed from "Welcome" to "emocleW"
and similarly all other wrods are reversed but the order of the words is same, I have written this Solution Code: function reverseBySeparator(string, separator) {
return string.split(separator).reverse().join(separator);
}
function reverseWords (str){
const step1 = reverseBySeparator(str,"")
const step2 = reverseBySeparator(step1," ")
console.log(step2)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a string, reverse each word in the sentenceA string containing multiple words
ex:- "Welcome to this Javascript Guide!"A string with all words reversed
ex:- "emocleW ot siht tpircsavaJ !ediuG"Sample input:-
"Welcome to this Javascript Guide!"
Sample output:-
"emocleW ot siht tpircsavaJ !ediuG"
Explanation:-
The first word is reversed from "Welcome" to "emocleW"
and similarly all other wrods are reversed but the order of the words is same, I have written this Solution Code: import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Stack;
import static java.lang.Math.pow;
class InputReader {
private boolean finished = false;
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public static InputReader getInputReader(boolean readFromTextFile) throws FileNotFoundException {
return ((readFromTextFile) ? new InputReader(new FileInputStream("src/input.txt"))
: new InputReader(System.in));
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String nextString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c)) {
res.appendCodePoint(c);
}
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuilder buf = new StringBuilder();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r') {
buf.appendCodePoint(c);
}
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0) {
s = readLine0();
}
return s;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E') {
return res * pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E') {
return res * pow(10, nextInt());
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public int[] nextSortedIntArray(int n) {
int array[] = nextIntArray(n);
Arrays.sort(array);
return array;
}
public int[] nextSumIntArray(int n) {
int[] array = new int[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; ++i) array[i] = nextLong();
return array;
}
public long[] nextSumLongArray(int n) {
long[] array = new long[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextSortedLongArray(int n) {
long array[] = nextLongArray(n);
Arrays.sort(array);
return array;
}
}
class Main {
public static void main(String[] args) throws FileNotFoundException {
InputReader sc = InputReader.getInputReader(false);
String str = sc.readLine();
char[] charArray = str.toCharArray();
Stack<Character> st = new Stack<>();
for (int i = 0; i < charArray.length; i++) {
while (i < charArray.length && charArray[i] != ' ') {
st.push(charArray[i]);
i++;
}
while (!st.isEmpty()) {
System.out.print(st.pop());
}
System.out.print(" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments.
<b>A[]:</b> input array
<b>start:</b> starting index of array
<b>end</b>: ending index of array
Constraints
1 <= T <= 1000
1 <= N <= 10^4
1 <= A[i] <= 10^5
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code: def partition(array, low, high):
pivot = array[high]
i = low - 1
for j in range(low, high):
if array[j] <= pivot:
i = i + 1
(array[i], array[j]) = (array[j], array[i])
(array[i + 1], array[high]) = (array[high], array[i + 1])
return i + 1
def quick_sort(array, low, high):
if low < high:
pi = partition(array, low, high)
quick_sort(array, low, pi - 1)
quick_sort(array, pi + 1, high)
t=int(input())
for i in range(t):
n=int(input())
a=input().strip().split()
a=[int(i) for i in a]
quick_sort(a, 0, n - 1)
for i in a:
print(i,end=" ")
print(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments.
<b>A[]:</b> input array
<b>start:</b> starting index of array
<b>end</b>: ending index of array
Constraints
1 <= T <= 1000
1 <= N <= 10^4
1 <= A[i] <= 10^5
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code:
public static int[] quickSort(int arr[], int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(arr, low, high);
// Recursively sort elements before
// partition and after partition
quickSort(arr, low, pi-1);
quickSort(arr, pi+1, high);
}
return arr;
}
public static int partition(int arr[], int low, int high)
{
int pivot = arr[high];
int i = (low-1); // index of smaller element
for (int j=low; j<high; j++)
{
// If current element is smaller than the pivot
if (arr[j] < pivot)
{
i++;
// swap arr[i] and arr[j]
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// swap arr[i+1] and arr[high] (or pivot)
int temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
return i+1;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array <b>A[]</b> having <b>N</b> positive integers. You need to arrange these elements in increasing order using <b>Quick Sort</b> algorithm.<b>User Task:</b>
Since this is a functional problem you don't have to worry about the input. You just have to complete the function <b>quickSort()</b> which contains following arguments.
<b>A[]:</b> input array
<b>start:</b> starting index of array
<b>end</b>: ending index of array
Constraints
1 <= T <= 1000
1 <= N <= 10^4
1 <= A[i] <= 10^5
<b>Sum of "N" over all testcases does not exceed 10^5</b>For each testcase you need to return the sorted array. The driver code will do the rest.Sample Input:
2
3
3 1 2
3
4 5 6
Sample Output:
1 2 3
4 5 6, I have written this Solution Code: function quickSort(arr, low, high)
{
if(low < high)
{
let pi = partition(arr, low, high);
quickSort(arr, low, pi-1);
quickSort(arr, pi+1, high);
}
return arr;
}
function partition(arr, low, high)
{
let pivot = arr[high];
let i = (low-1); // index of smaller element
for (let j=low; j<high; j++)
{
// If current element is smaller than the pivot
if (arr[j] < pivot)
{
i++;
// swap arr[i] and arr[j]
let temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
// swap arr[i+1] and arr[high] (or pivot)
let temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
return i+1;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 β€ T β€ 100
0 β€ M, N β€ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: static int Multiply(int n, int m)
{
if(n==0 || m==0){return 0;}
if (m == 1)
{ return n;}
return n + Multiply(n,m-1);
} , In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two numbers m and n, multiply them using only "addition" operations.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Multiply()</b> that takes the integer M and N as a parameter.
Constraints:
1 β€ T β€ 100
0 β€ M, N β€ 100Return the product of N and M.Sample Input
2
2 3
3 4
Sample Output
6
12, I have written this Solution Code: def multiply_by_recursion(n,m):
# Base Case
if n==0 or m==0:
return 0
# Recursive Case
if m==1:
return n
return n + multiply_by_recursion(n,m-1)
# Driver Code
t=int(input())
while t>0:
l=list(map(int,input().strip().split()))
n=l[0]
m=l[1]
print(multiply_by_recursion(n,m))
t=t-1, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to check if the given number prime or not.<b>User Task</b>
Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Ifprime()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 10<sup>9</sup>
<b>Note:</b>
<i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Print "Yes" if the given number is prime else print "No"Sample Input:-
6
Sample Output:-
No
Sample Input:-
3
Sample Output:-
Yes, I have written this Solution Code: def IFprime(N):
is_prime = 'Yes'
if N == 1: is_prime = 'No'
else:
for i in range(2, N//2+1):
if N % i == 0:
is_prime = 'No'
break
print(is_prime)
IFprime(int(input())), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a positive integer N, your task is to check if the given number prime or not.<b>User Task</b>
Since this is a functional problem, you don't have to worry about the input. You just have to complete the function <i>Ifprime()</i> which contains the given number N.
<b>Constraints:</b>
1 <= N <= 10<sup>9</sup>
<b>Note:</b>
<i>But there is a catch here given user function has already code in it which may or may not be correct, now you need to figure out these and correct if it is required</i>Print "Yes" if the given number is prime else print "No"Sample Input:-
6
Sample Output:-
No
Sample Input:-
3
Sample Output:-
Yes, I have written this Solution Code: static void Ifprime(int N)
{
if(N==1){
System.out.print("No");
return;
}
boolean prime = true;
for(int i=2; i*i<=N ;i++){
if(N%i==0){prime=false;break;}
}
if(prime==true){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N elements. Find the maximum value of GCD(Arr[i], Arr[j]) where i != j.First line of input contains a single integer N.
Second line of input contains N space separated integers, denoting array Arr.
Constraints:
2 <= N <= 100000
1 <= Arr[i] <= 100000Print the maximum value of GCD(Arr[i], Arr[j]) where i != j.Sample Input 1
5
2 4 5 2 2
Sample Output 1
2
Explanation: We can select index 1 and index 4, GCD(2, 2) = 2
Sample Input 2
6
4 3 4 1 6 5
Sample Output 2
4, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
static int result(int a[],int n)
{
int maxe =0;
for(int i=0;i<n;i++)
maxe = Math.max(maxe,a[i]);
int count[]=new int[maxe+1];
for(int i=0;i<n;i++)
{
for(int j=1;j<Math.sqrt(a[i]);j++)
{
if(a[i]%j==0)
{
count[j]++;
if (j != a[i] / j)
count[a[i] / j]++;
}
}
}
for(int i=maxe;i>0;i--)
{
if(count[i]>1)
return i;
}
return 1;
}
public static void main (String[] args) throws IOException{
InputStreamReader i = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(i);
int n = Integer.parseInt(br.readLine());
int a[] = new int[n];
String str = br.readLine();
String[] strs = str.trim().split(" ");
for (int j = 0; j < n; j++)
{
a[j] = Integer.parseInt(strs[j]);
}
System.out.println(result(a,n));
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array Arr of N elements. Find the maximum value of GCD(Arr[i], Arr[j]) where i != j.First line of input contains a single integer N.
Second line of input contains N space separated integers, denoting array Arr.
Constraints:
2 <= N <= 100000
1 <= Arr[i] <= 100000Print the maximum value of GCD(Arr[i], Arr[j]) where i != j.Sample Input 1
5
2 4 5 2 2
Sample Output 1
2
Explanation: We can select index 1 and index 4, GCD(2, 2) = 2
Sample Input 2
6
4 3 4 1 6 5
Sample Output 2
4, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int v[100001]={};
int n;
cin>>n;
for(int i=1;i<=n;++i){
int d;
cin>>d;
for(int j=1;j*j<=d;++j){
if(d%j==0){
v[j]++;
if(j!=d/j)
v[d/j]++;
}
}
}
for(int i=100000;i>=1;--i)
if(v[i]>1){
cout<<i;
return 0;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a doubly linked list consisting of N nodes and two integers <b>P</b> and <b>K</b>. Your task is to add an element K at the Pth position from the start of the linked list<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>insertnew()</b>. The description of parameters are mentioned below:
<b>head</b>: head node of the double linked list
<b>K</b>: the element which you have to insert
<b>P</b>: the position at which you have insert
Constraints:
1 <= P <=N <= 1000
1 <=K, Node.data<= 1000
In the sample Input N, P and K are in the order as mentioned below:
<b>N P K</b>Return the head of the modified linked list.Sample Input:-
5 3 2
1 3 2 4 5
Sample Output:-
1 3 2 2 4 5, I have written this Solution Code: public static Node insertnew(Node head, int k,int pos) {
int cnt=1;
if(pos==1){Node temp=new Node(k);
temp.next=head;
head.prev=temp;
return temp;}
Node temp=head;
while(cnt!=pos-1){
temp=temp.next;
cnt++;
}
Node x= new Node(k);
x.next=temp.next;
temp.next.prev=x;
temp.next=x;
x.prev=temp;
return head;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, find the count of pairs of indices <b>i</b> and <b>j</b> such that <b>1 <= i < j <= N</b> and the <b>mean</b> of elements at these indices is at least <b>K</b>.
More formally, you have to find the number of indices <b>i</b> and <b>j</b> such that <b>1 <= i < j <= N</b> and (A<sub>i</sub> + A<sub>j</sub>)/2 >= KFirst line of the input contains two integers N and K.
The second line contains N space seperated integers A<sub>i</sub>
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= K <= 10<sup>9</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the number of pairs satisfying the above condition in array A.Sample Input:
5 6
4 7 8 2 5
Sample Output:
4
Explaination:
The following pairs of indices satisfy the condition (1-based indexing)
(1, 3) -> (4 + 8)/2 = 6
(2, 3) -> (7 + 8)/2 = 7.5
(2, 5) -> (7 + 5)/2 = 6
(3, 5) -> (8 + 5)/2 = 6.5
There are no more pairs of indices that satisfy the above condition., I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve() {
int n, k;
cin >> n >> k;
assert(1 <= n <= 1e5);
assert(1 <= k <= 1e9);
vector<int> a(n);
for (auto &i : a) cin >> i, assert(1 <= i <= 1e9);
sort(all(a));
int ans = 0;
int req_sum = 2 * k;
for (int i = 0; i < n; i++) {
int x = req_sum - a[i];
x = max(x, (int)0);
int l = i + 1, r = n - 1, ind = n;
while (l <= r) {
int m = (l + r) / 2;
if (a[m] >= x) {
r = m - 1;
ind = m;
} else
l = m + 1;
}
ans += n - ind;
}
cout << ans;
}
signed main() {
fast int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
if (i != t) cout << endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A of size N, find the count of pairs of indices <b>i</b> and <b>j</b> such that <b>1 <= i < j <= N</b> and the <b>mean</b> of elements at these indices is at least <b>K</b>.
More formally, you have to find the number of indices <b>i</b> and <b>j</b> such that <b>1 <= i < j <= N</b> and (A<sub>i</sub> + A<sub>j</sub>)/2 >= KFirst line of the input contains two integers N and K.
The second line contains N space seperated integers A<sub>i</sub>
Constraints:
1 <= N <= 10<sup>5</sup>
1 <= K <= 10<sup>9</sup>
1 <= A<sub>i</sub> <= 10<sup>9</sup>Print the number of pairs satisfying the above condition in array A.Sample Input:
5 6
4 7 8 2 5
Sample Output:
4
Explaination:
The following pairs of indices satisfy the condition (1-based indexing)
(1, 3) -> (4 + 8)/2 = 6
(2, 3) -> (7 + 8)/2 = 7.5
(2, 5) -> (7 + 5)/2 = 6
(3, 5) -> (8 + 5)/2 = 6.5
There are no more pairs of indices that satisfy the above condition., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nk=br.readLine();
String nkarr[]=nk.split(" ");
int n =Integer.parseInt(nkarr[0]);
int k =Integer.parseInt(nkarr[1]);
String ss = br.readLine();
String sst[]=ss.split(" ");
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(sst[i]);
}
long val = findMean(arr,n,k);
System.out.println(val);
}
public static long findMean(int []arr,int n,int k){
Arrays.sort(arr);
int low =0;
int high=arr.length-1;
long ans=0;
while(low<high){
long mean =(arr[low]+arr[high])/2;
if(mean>=k){
ans+=(high-low);
high--;
}else{
low++;
}
}
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function selectionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] str = br.readLine().split(" ");
int a[] = new int[n];
for(int i=0; i<n; i++){
a[i] = Integer.parseInt(str[i]);
}
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
if(a[i]>a[j]){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int i=0; i<n; i++){
System.out.print(a[i]+" ");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: def selectionSort(arr):
arr.sort()
return arr
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Implement Selection Sort on a given array, and make it sorted.First line of the input contains an integer, N, which denotes the length of the array. Next N inputs are elements of the array that is to be sorted in ascending order.
Constraints
1<=N<=1000
-10000<=Arr[i]<=10000Sorted output where each element is space separatedSample Input:
3
3 1 2
Sample Output:
1 2 3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code:
void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: public static void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: function patternMaking(N)
{
for(let j=1; j <= 2*N - 1; j++) {
let k;
if(j<= N) {
k = j;
} else {
k = 2*N - j;
}
let res = "";
for(let i=1; i<=2*k-1; i++) {
if(i<=k) {
res += i + " ";
} else {
res += 2*k - i + " ";
}
}
console.log(res);
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: def pattern_making(n):
for i in range(1, n+1):
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=n-1
while i>=1 :
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=i-1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code:
void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: public static void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: function patternMaking(N)
{
for(let j=1; j <= 2*N - 1; j++) {
let k;
if(j<= N) {
k = j;
} else {
k = 2*N - j;
}
let res = "";
for(let i=1; i<=2*k-1; i++) {
if(i<=k) {
res += i + " ";
} else {
res += 2*k - i + " ";
}
}
console.log(res);
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: def pattern_making(n):
for i in range(1, n+1):
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=n-1
while i>=1 :
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=i-1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: class Solution {
public static int Rare(int n, int k){
while(n>0){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code: def Rare(N,K):
while N>0:
if(N%10)%K!=0:
return 0
N=N//10
return 1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number s called rare if all of its digits are divisible by K. Given a number N your task is to check if the given number is rare or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>Rare()</b> that takes integer N and K as arguments.
Constraints:-
1 <= N <= 100000
1 <= K <= 9Return 1 if the given number is rare else return 0.Sample Input:-
2468 2
Sample Output:-
1
Sample Input:-
234 2
Sample Output:-
0
Explanation :
3 is not divisible by 2., I have written this Solution Code:
int Rare(int n, int k){
while(n){
if((n%10)%k!=0){
return 0;
}
n/=10;
}
return 1;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given a sequence of 5 integers A. Initially, A<sub>i</sub> (1 ≤ i ≤ 5) assigns i.
But due to some glitch, one of the integers in the array becomes 0.
Find out which integer of A assigned 0.The first line contains 5 integers A<sub>1</sub>, A<sub>2</sub> ... A<sub>5</sub>.
<b>Constraints</b>
The values of A<sub>1</sub>, A<sub>2</sub>, A<sub>3</sub>, A<sub>4</sub>, A<sub>5</sub> given as input are a possible outcome of the assignment.If the integer assigned 0 was A<sub>i</sub>, print the integer i.<b>Sample Input 1:</b>
0 2 3 4 5
<b>Sample Output 1:</b>
1
<b>Sample Input 2:</b>
1 2 0 4 5
<b>Sample Output 2:</b>
3, I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define all(a) a.begin(),a.end()
int main(){
for(int i=0; i<5; ++i){
int x;
cin >> x;
if(x==0) cout << i+1 << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: def area(side_of_square):
print(side_of_square*side_of_square)
def main():
N = int(input())
area(N)
if __name__ == '__main__':
main(), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a side of a square, your task is to calculate and print its area.The first line of the input contains the side of the square.
<b>Constraints:</b>
1 <= side <=100You just have to print the area of a squareSample Input:-
3
Sample Output:-
9
Sample Input:-
6
Sample Output:-
36, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int side = Integer.parseInt(br.readLine());
System.out.print(side*side);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Take an integer as input and print it.The first line contains integer as input.
<b>Constraints</b>
1 <= N <= 10Print the input integer in a single lineSample Input:-
2
Sample Output:-
2
Sample Input:-
4
Sample Output:-
4, I have written this Solution Code: /* 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 Main
{
public static void printVariable(int variable){
System.out.println(variable);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
printVariable(num);
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] st = bf.readLine().split(" ");
if(Integer.parseInt(st[1])==0)
System.out.print(-1);
else {
int f = (Integer.parseInt(st[0])/Integer.parseInt(st[1]));
System.out.print(f);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: D,Q = input().split()
D = int(D)
Q = int(Q)
if(0<=D and Q<=100 and Q >0):
print(int(D/Q))
else:
print('-1'), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nobita wants to score well in his upcoming test, but he is not able to solve the simple division problems, seeing Nobita's determination Doraemon gives him a gadget that can do division problems easily but somehow Nobita deleted the internal program which calculates the division.
As an excellent coder, Nobita came to you for help. Help Nobita to write a code for his gadget.
You will be given two integers <b>D</b> and <b>Q</b>, you have to print the value of <b>D/Q</b> rounded down .The input contains two space- separated integers depicting the values of D and Q.
Constraints:-
0 <= D, Q <= 100Print the values of D/Q if the value can be calculated else print -1 if it is undefined.
Note:- Remember division by 0 is an undefined value that will give runtime error in your program.Sample Input:-
9 3
Sample Output:-
3
Sample Input:-
8 5
Sample Output:-
1
Explanation:-
8/5 = 1.6 = 1(floor), I have written this Solution Code: #include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
if(m==0){cout<<-1;return 0;}
cout<<n/m;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: static int focal_length(int R, char Mirror)
{
int f=R/2;
if((R%2==1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code:
int focal_length(int R, char Mirror)
{
int f=R/2;
if((R&1) && Mirror==')'){f++;}
if(Mirror == ')'){f=-f;}
return f;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given the length of the radius of curvature and the type of mirror, calculate its focal length.
<b>Note:</b> '(' represents a convex mirror while ')' represents a concave mirror<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>focal_length()</b> that takes the integer R(radius of curvature) and the character Mirror (type of mirror) as parameter
<b>Constraints:-</b>
1 <= R <= 100
Mirror will be either of '('(convex type) or ')'(concave type)Return the <b>floor value of focal length.</b>Sample Input:-
9 (
Sample Output:-
4
Sample Input:-
9 )
Sample Output:-
-5, I have written this Solution Code: def focal_length(R,Mirror):
f=R/2;
if(Mirror == ')'):
f=-f
if R%2==1:
f=f-1
return int(f)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: // arr is unsorted array
// n is the number of elements in the array
function insertionSort(arr, n) {
// write code here
// do not console.log the answer
// return sorted array
return arr.sort((a, b) => a - b)
}
, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void insertionSort(int[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1; j < arr.length; j++){
if(arr[i] > arr[j]){
int temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T > 0){
int n = scan.nextInt();
int arr[] = new int[n];
for(int i = 0; i<n; i++){
arr[i] = scan.nextInt();
}
insertionSort(arr);
for(int i = 0; i<n; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
T--;
System.gc();
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: #include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int a[N];
signed main() {
IOS;
int t; cin >> t;
while(t--){
int n; cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an array A[] of size N, containing positive integers. You need to sort the elements of array using Insertion sort algorithm.First line of the input denotes number of test cases T. First line of the testcase is the size of array N and second line consists of array elements separated by space.
Constraints:
1 <= T <= 100
1 <= N <= 10^3
1 <= A[i] <= 10^3For each testcase print the sorted array in a new line.Input:
2
5
4 1 3 9 7
10
10 9 8 7 6 5 4 3 2 1
Output:
1 3 4 7 9
1 2 3 4 5 6 7 8 9 10
Explanation:
Testcase 1: The array after perfoming insertion sort: 1 3 4 7 9.
Testcase 2: The array after performing insertion sort: 1 2 3 4 5 6 7 8 9 10., I have written this Solution Code: def InsertionSort(arr):
arr.sort()
return arr, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: m,n = map(int , input().split())
if (m%n==0):
print("Yes")
else:
print("No");, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code: #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long
#define f80 __float128
#define pii pair<int,int>
/////////////
signed main()
{
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in","r",stdin);
freopen("outputf.in","w",stdout);
#endif
int n,m;
cin>>n>>m;
if(n%m==0)
cout<<"Yes";
else
cout<<"No";
#ifdef ANIKET_GOYAL
// cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N and M check if N candies can be divided in M people such that each person get equal number of candies.Input contains two integers N and M.
Constraints:
1 <= N <= 10^18
1 <= M <= 10^18Print "Yes" if it is possible otherwise "No".Sample Input
10 5
Sample Output
Yes
Explanation: Give 2 candies to all.
Sample Input:
4 3
Sample Output:
No, I have written this Solution Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Long m = sc.nextLong();
if(n%m==0){
System.out.print("Yes");
}
else{
System.out.print("No");
}
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code: static int maximumMarks(int X){
if(X>5){
return X;
}
return 10-X;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code:
int maximumMarks(int X){
if(X>5){
return X;
}
return 10-X;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code: def maximumMarks(X):
if X>5:
return (X)
return (10-X)
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Sara is giving a True False exam consisting of 10 questions. In which she knows that exactly X of the given questions are True and the rest are false (thanks to her friend) but she does not know the order. This time she decided to fill it optimally so that in any case she can get the maximum of minimum marks possible.
Given the value of X, your task is to tell Sara what can be the maximum of minimum marks she can get. i. e out of every minimum mark for a different number of True and False what will be the maximum of that minimum.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>maximumMarks()</b> that takes integer X as argument.
Constraints:-
0 <= X <= 10Return the maximum marks of all the minimum possible.Sample Input:-
X = 5
Sample Output:-
5
Explanation:-
One of the possible solutions is she can mark all the answers true.
Sample Input:-
1
Sample Output:-
9, I have written this Solution Code:
int maximumMarks(int X){
if(X>5){
return X;
}
return 10-X;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: int PerfectNumber(int N){
int ans=0;
while(N>0){
ans+=N%10;
N/=10;
}
if(ans%5==0){return 1;}
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: int PerfectNumber(int N){
int ans=0;
while(N>0){
ans+=N%10;
N/=10;
}
if(ans%5==0){return 1;}
return 0;
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: static int PerfectNumber(int N){
int ans=0;
while(N>0){
ans+=N%10;
N/=10;
}
if(ans%5==0){return 1;}
return 0;
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: A number is said to be perfect if the sum of its digits is divisible by 5. Given a number N check if it is perfect or not.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>PerfectNumber()</b> that takes integer N as argument.
Constraints:-
1 <= N <= 10000Return 1 if the given number is perfect else return 0.Sample Input:-
122
Sample Output:-
1
Explanation:-
1 + 2 + 2 = 5 which is divisible by 5
Sample Input:-
123
Sample Output:-
0, I have written this Solution Code: def PerfectNumber(N):
cnt=0
while N>0:
cnt=cnt+int(N%10)
N=int(N/10)
if (cnt%5==0):
return 1
return 0
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Palindrome is a word, phrase, or sequence that reads the same backwards as forwards. Use recursion to check if a given string is palindrome or not.User Task:
Since this is a functional problem, you don't have to worry about the input, you just have to complete the function check_Palindrome() where you will get input string, starting index of string (which is 0) and the end index of string( which is str.length-1) as argument.
Constraints:
1 β€ T β€ 100
1 β€ N β€ 10000Return true if given string is palindrome else return falseSample Input
2
ab
aba
Sample Output
false
true, I have written this Solution Code:
static boolean check_Palindrome(String str,int s, int e)
{
// If there is only one character
if (s == e)
return true;
// If first and last
// characters do not match
if ((str.charAt(s)) != (str.charAt(e)))
return false;
// If there are more than
// two characters, check if
// middle substring is also
// palindrome or not.
if (s < e + 1)
return check_Palindrome(str, s + 1, e - 1);
return true;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: #include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define ma 10000001
bool a[ma];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++){
a[i]=false;
}
for(int i=2;i<=n;i++){
if(a[i]==false){
for(int j=i+i;j<=n;j+=i){
a[j]=true;
}
}
}
int cnt=0;
for(int i=2;i<=n;i++){
if(a[i]==false){cnt++;}
}
cout<<cnt;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.lang.Math;
class Main {
public static void main (String[] args)
throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = Integer.parseInt(br.readLine());
long i=2,j,count,noOfPrime=0;
if(n<=1)
System.out.println("0");
else{
while(i<=n)
{
count=0;
for(j=2; j<=Math.sqrt(i); j++)
{
if( i%j == 0 ){
count++;
break;
}
}
if(count==0){
noOfPrime++;
}
i++;
}
System.out.println(noOfPrime);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: function numberOfPrimes(N)
{
let arr = new Array(N+1);
for(let i = 0; i <= N; i++)
arr[i] = 0;
for(let i=2; i<= N/2; i++)
{
if(arr[i] === -1)
{
continue;
}
let p = i;
for(let j=2; p*j<= N; j++)
{
arr[p*j] = -1;
}
}
//console.log(arr);
let count = 0;
for(let i=2; i<= N; i++)
{
if(arr[i] === 0)
{
count++;
}
}
//console.log(arr);
return count;
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number n find the number of prime numbers less than equal to that number.There is only one integer containing value of n.
Constraints:-
1 <= n <= 10000000Return number of primes less than or equal to nSample Input
5
Sample Output
3
Explanation:-
2 3 and 5 are the required primes.
Sample Input
5000
Sample Output
669, I have written this Solution Code: import math
n = int(input())
n=n+1
if n<3:
print(0)
else:
primes=[1]*(n//2)
for i in range(3,int(math.sqrt(n))+1,2):
if primes[i//2]:primes[i*i//2::i]=[0]*((n-i*i-1)//(2*i)+1)
print(sum(primes)), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: a="Hello World"
print(a), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: When learning a new language, we first learn to output some message. Here, we'll start with the famous "Hello World" message. There is no input, you just have to print "Hello World".No InputHello WorldExplanation:
Hello World is printed., I have written this Solution Code: import java.util.*;
import java.io.*;
class Main{
public static void main(String args[]){
System.out.println("Hello World");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import math
n = int(input())
for i in range(n):
x = int(input())
count = 0
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0:
if (i%2 == 0):
count+=1
if ((x/i) %2 == 0):
count+=1
print(count), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
int n = Integer.parseInt(br.readLine());
int count=0;
for(int i=1;i<=Math.sqrt(n);i++){
if(n%i == 0)
{
if(i%2==0) {
count++;
}
if(i*i != n && (n/i)%2==0) {
count++;
}
}
}
System.out.println(count);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer N, the task is to find the number of divisors of N which are divisible by 2.The input line contains T, denoting the number of testcases. First line of each testcase contains integer N
Constraints:
1 <= T <= 50
1 <= N <= 10^9For each testcase in new line, you need to print the number of divisors of N which are exactly divisble by 2Input:
2
9
8
Output
0
3, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
cin>>n;
if(n&1){cout<<0<<endl;continue;}
long x=sqrt(n);
int cnt=0;
for(long long i=1;i<=x;i++){
if(!(n%i)){
if(!(i%2)){cnt++;}
if(i*i!=n){
if(!((n/i)%2)){cnt++;}
}
}
}
cout<<cnt<<endl;}
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given two numbers n and p. You need to find n raised to the power p.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>RecursivePower</b> that takes the integer n and p as a parameter.
Constraints:
1 <= T <= 10
1 <= n, p <= 9Return n^p.Sample Input:
3
2 3
9 9
2 9
Sample Output:
8
387420489β¬
512
Explanation:
Test case 2: 387420489 is the value obtained when 9 is raised to the power of 9.
Test case 3: 512 is the value obtained when 2 is raised to the power of 9, I have written this Solution Code:
static int Power(int n,int p)
{
if(p==0)
return 1;
return n*Power(n,p-1);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
cout<<j<<" ";
}
for(int j=i-1;j>=1;j--){
cout<<j<<" ";
}
cout<<endl;
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code:
void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
printf("%d ",j);
}
for(int j=i-1;j>=1;j--){
printf("%d ",j);
}
printf("\n");
}
}, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: public static void pattern_making(int n){
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
for(int i=n-1;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
for(int j=i-1;j>=1;j--){
System.out.print(j+" ");
}
System.out.println();
}
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: function patternMaking(N)
{
for(let j=1; j <= 2*N - 1; j++) {
let k;
if(j<= N) {
k = j;
} else {
k = 2*N - j;
}
let res = "";
for(let i=1; i<=2*k-1; i++) {
if(i<=k) {
res += i + " ";
} else {
res += 2*k - i + " ";
}
}
console.log(res);
}
}, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n, your task is to print the pattern as shown in example:-
For n=5, the pattern is:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>pattern_making()</b> that takes the integer n as parameter.
Constraints:-
1 <= n <= 100Print the pattern as shown.Sample Input:-
5
Sample output:-
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
Sample Input:-
2
Sample Output:-
1
1 2 1
1, I have written this Solution Code: def pattern_making(n):
for i in range(1, n+1):
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=n-1
while i>=1 :
for j in range(1, i+1):
print(j,end=" ")
for j in range (1,i):
print(i-j,end=" ")
print("\r")
i=i-1
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: a, b = list(map(int, input().split(" ")))
print(str(a <= 10 and b >= 10).lower(), end=' ')
print(str(a % 2 == 0 or b % 2 == 0).lower(), end=' ')
print(str(not a == b).lower()), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given two integers a and b, your task is to check following conditions:-
1. If a <= 10 and b >= 10 (Logical AND).
2. Atleast one from a or b will be even (Logical OR).
3. if a is not equal to b (Logical NOT).The first line of the input contains 2 integers a and b.
<b>Constraints:</b>
1 <= a, b <= 100Print the string <b>"true"</b> if the condition holds in each function else <b>"false"</b> .
Sample Input:-
3 12
Sample Output:-
true true true
Explanation
So a = 3 and b = 12, so a<=10 and b>=10 hence first condition true, a is not even but b is even so atleast one of them is even hence true, third a != b which is also true hence the final output comes true true true.
Sample Input:-
10 10
Sample Output:-
true true false
, I have written this Solution Code: import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Main {
static boolean Logical_AND(int a, int b){
if(a<=10 && b>=10){
return true;}
return false;}
static boolean Logical_OR(int a, int b){
if(a%2==0 || b%2==0){
return true;}
return false;}
static boolean Logical_NOT(int a, int b){
if(a!=b){
return true;}
return false;}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.print(Logical_AND(a, b)+" ");
System.out.print(Logical_OR(a,b)+" ");
System.out.print(Logical_NOT(a,b)+" ");
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: You are given an array of integers. Consider absolute difference between all the pairs of the the elements. You need to find Kth smallest absolute difference. If the size of the array is N then value of K will be less than N and more than or equal to 1.The first line of input contains number of test cases T.
The first line of each test case contains a two integers N and K denoting the number of elements in the array A and difference you need to output. The second line of each test case contains N space separated integers denoting the elements of the array A
Constraints:
1<= T <= 10
2 <= N <= 100000
1 <= K < N < 100000
0 <= A[i] <= 100000For each test case, output Kth smallest absolute difference.Input :
1
6 2
1 3 4 1 3 8
Output :
0
Explanation :
Test case 1: First smallest difference is 0, between the pair (1, 1) and second smallest absolute difference difference is also 0 between the pairs (3, 3)., I have written this Solution Code: import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
public static void main(String[] args)throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine().trim());
while (t-- > 0) {
String str[] = read.readLine().trim().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
int arr[] = new int[n];
str = read.readLine().trim().split(" ");
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(str[i]);
System.out.println(Math.abs(small(arr, k)));
}
}
public static int small(int arr[], int k) {
Arrays.sort(arr);
int l = 0, r = arr[arr.length - 1] - arr[0];
while (r > l) {
int mid = l + (r - l) / 2;
if (count(arr, mid) < k) {
l = mid + 1;
} else {
r = mid;
}
}
return r;
}
public static int count(int arr[], int mid) {
int ans = 0, j = 0;
for (int i = 1; i < arr.length; ++i) {
while (j < i && arr[i] - arr[j] > mid) {
++j;
}
ans += i - j;
}
return ans;
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Four players participate in the playoff tournament. The tournament is held according to the following scheme:
<ul>
<li>the first player will play with the second, and</li>
<li>the third player with the fourth, then</li>
<li>the winners of the pairs will play in the finals of the tournament.</li>
</ul>
It is known that in a match between two players, the one whose skill is greater will win. The skill of the ith player is equal to s<sub>i</sub> and all skill levels are pairwise different (i.e. there are no two identical values in the array s).
The tournament is called fair if the two players with the highest skills meet in the finals. Determine whether the given tournament is fair.The input consists of 4 space- spearated integers s<sub>1</sub>, s<sub>2</sub>, s<sub>3</sub>, s<sub>4</sub>.
<b>Constraints</b>
1 ≤ s<sub>i</sub> ≤ 100Print Yes if the tournament is fair, or No otherwise.<b>Sample Input 1</b>
3 7 9 5
<b>Sample Output 1</b>
Yes
<b>Sample Input 2</b>
4 5 6 9
<b>Sample Output 2</b>
No, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int t=1;
// cin >> t;
for (int i = 0; i < t; i++){
vector<int> s(4);
for (int j = 0; j < 4; j++){
cin >> s[j];
}
int m1 = max(s[0], s[1]);
int m2 = max(s[2], s[3]);
if (m1 > m2){
swap(m1, m2);
}
sort(s.begin(), s.end());
if (s[2] == m1 && s[3] == m2){
cout << "Yes" << "\n";
} else {
cout << "No" << "\n";
}
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
int cost(int n){
if(n == 0) return 0;
int g = (n-1)/3 + 1;
return g*g + cost(n-g);
}
signed main() {
IOS;
clock_t start = clock();
int q; cin >> q;
while(q--){
int n;
cin >> n;
cout << cost(n) << endl;
}
cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms" << endl;
return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: John has N candies. He wants to crush all of them. He feels that it would be boring to crush the candies randomly, so he found a method to crush them. He divides these candies into a minimum number of groups such that no group contains more than 3 candies. He crushes one candy from each group. If there are G groups in a single step, then the cost incurred in crushing a single candy for that step is G dollars. After candy from each group is crushed, he takes all the remaining candies and repeats the process until he has no candies left. He hasn't started crushing yet, but he wants to know how much the total cost would be incurred. Can you help him?
You have to answer Q-independent queries.The first line of input contains a single integer, Q denoting the number of queries.
Next, Q lines contain a single integer N denoting the number of candies John has.
<b>Constraints</b>
1 <= Q <= 5 * 10^4
1 <= N <= 10^9Print Q lines containing total cost incurred for each query.Sample Input 1:
1
4
Sample Output 1:
6
<b>Explanation:</b>
Query 1: First step John divides the candies into two groups of 3 and 1 candy respectively. Crushing one-one candy from both groups would cost him 2x2 = 4 dollars. He is now left with 2 candies. He divides it into one group. He crushes one candy for 1 dollar. Now, he is left with 1 candy. He crushes the last candy for 1 dollar. So, the total cost incurred is 4+1+1 = 6 dollars., I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in)
);
long q = Long.parseLong(br.readLine());
while(q-->0)
{
long N = Long.parseLong(br.readLine());
System.out.println(candyCrush(N,0,0));
}
}
static long candyCrush(long N, long cost,long group)
{
if(N==0)
{
return cost;
}
if(N%3==0)
{
group = N/3;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
else
{
group = (N/3)+1;
cost = cost + (group*group);
return candyCrush(N-group,cost,0);
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nishu is trying to clean a room, which is divided up into an N by N grid of squares. Each square is initially either clean or dirty. She can sweep her broom over columns of the grid. Her broom is very strange:
if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean.
She wants to sweep some columns of the room to maximize the number of completely clean rows. It is not allowed to sweep over the part of the column, Nishu can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.The first line of the input contains a single integer N.
The next N lines will describe the state of the room. The i- th line will contain a binary string with N characters denoting the state of the i-th row of the room. The j- th character on this line is '1' if the j- th square in the i-th row is clean, and '0' if it is dirty.
Constraints:
1<=N<=100The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.Sample Input 1:
4
0101
1000
1111
0101
Sample output 1:
2
Explanations:
Nishu can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean., I have written this Solution Code: n = int(input())
arr = []
for i in range(n):
string = str(input())
string = string[:4]
arr.append(string)
rows = 0
for i in range(n):
count = 0
for j in range(n):
if arr[i] == arr[j]:
count += 1
rows = max(rows,count)
print(rows), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Nishu is trying to clean a room, which is divided up into an N by N grid of squares. Each square is initially either clean or dirty. She can sweep her broom over columns of the grid. Her broom is very strange:
if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean.
She wants to sweep some columns of the room to maximize the number of completely clean rows. It is not allowed to sweep over the part of the column, Nishu can only sweep the whole column.
Return the maximum number of rows that she can make completely clean.The first line of the input contains a single integer N.
The next N lines will describe the state of the room. The i- th line will contain a binary string with N characters denoting the state of the i-th row of the room. The j- th character on this line is '1' if the j- th square in the i-th row is clean, and '0' if it is dirty.
Constraints:
1<=N<=100The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean.Sample Input 1:
4
0101
1000
1111
0101
Sample output 1:
2
Explanations:
Nishu can sweep the 1st and 3rd columns. This will make the 1st and 4th row be completely clean., I have written this Solution Code: import java.util.Scanner;
public class Main
{
static String [] ar = new String[105];
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n = sc.nextInt();
for(int i=0;i<n;i++){
ar[i] = sc.next();
}
int ans = 0;
for(int i=0;i<n;i++){
int counter = 0;
for(int j=0;j<n;j++){
if(ar[i].equals(ar[j]))counter++;
}
ans = Math.max(ans, counter);
}
System.out.println(ans);
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Newton wants to take revenge from two apples fallen on his head. So, he applies force F<sub>1</sub> on first apple (mass M<sub>1</sub>) resulting in acceleration of A<sub>1</sub> and F<sub>2</sub> on second apple (mass M<sub>2</sub>) resulting in acceleration of A<sub>2</sub>. Given M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>. Calculate total force applied by him on two apples.
<b>Note:</b> F = M*A is the equation of relation between force, mass and acceleration.First line contains four integers M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub>.
1 <= M<sub>1</sub>, A<sub>1</sub>, M<sub>2</sub>, A<sub>2</sub> <= 100Output total force applied by Newton.INPUT:
1 2 3 4
OUTPUT:
14
Explanation:
Total force is equal to 1*2 + 3*4 = 14., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;
int main(){
int m1,a1,m2,a2;
cin >> m1 >> a1 >> m2 >> a2;
cout << (m1*a1)+(m2*a2) << endl;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int M=sc.nextInt();
int N=sc.nextInt();
for(int col=0;col<N;col++){
System.out.print("*");
}
System.out.println();
for(int row=0;row<M-2;row++){
System.out.print("*");
for(int col=0;col<N-2;col++){
System.out.print(" ");
}
System.out.print("*");
System.out.println();
}
for(int col=0;col<N;col++){
System.out.print("*");
}
}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: li = list(map(int,input().strip().split()))
m=li[0]
n=li[1]
for i in range(0,n):
if i==n-1:
print("*",end="\n")
else:
print("*",end="")
for i in range(1,m-1):
print("*",end="")
for j in range(0,n-2):
print(" ",end="")
print("*",end="\n")
for i in range(0,n):
print("*",end=""), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Give integer values M and N. Using the character β*β draw a rectangle of height M and breadth N.The input contains two integers M and N.
Constraints:-
3 <= M, N <= 20Print the rectangle as shown in the exampleSample Input:-
3 3
Sample Output:-
***
* *
***
Sample Input:-
5 3
Sample Output:-
***
* *
* *
* *
***, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
for(int i=0;i<n;i++){
cout<<'*';
}
cout<<endl;
m-=2;
while(m--){
cout<<'*';
for(int i=0;i<n-2;i++){
cout<<' ';
}
cout<<'*'<<endl;
}
for(int i=0;i<n;i++){
cout<<'*';
}
}, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: def firstTwo(N):
while(N>99):
N=N//10
return (N%10)*10 + N//10
, In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code:
int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: C, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given a number N your task is to print its first two digits in reverse order. For eg:- If the given number is 123 then the output will be 21.<b>User Task:</b>
Since this will be a functional problem, you don't have to take input. You just have to complete the function <b>firstTwo()</b> that takes integer N argument.
Constraints:-
111 <= N <= 9999
Note:- It is guaranteed that the given number will not contain any 0.Return the first two digits of the given number in reverse order.Sample Input:-
3423
Sample Output:-
43
Sample Input:-
1234
Sample Output:-
21, I have written this Solution Code: static int firstTwo(int N){
while(N>99){
N/=10;
}
int ans = (N%10)*10 + N/10;
return ans;
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: static void printDataTypes(int a, long b, float c, double d, char e)
{
System.out.println(a);
System.out.println(b);
System.out.printf("%.2f",c);
System.out.println();
System.out.printf("%.4f",d);
System.out.println();
System.out.println(e);
}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: void printDataTypes(int a, long long b, float c, double d, char e){
cout<<a<<endl;
cout<<b<<endl;
cout <<fixed<< std::setprecision(2) << c << '\n';
cout <<fixed<< std::setprecision(4) << d << '\n';
cout<<e<<endl;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Some Data types are given below:-
Integer
Long
float
Double
char
Your task is to take input in the given format and print them in the same order.You don't have to worry about input, you just have to complete the function <b>printDataTypes()</b>Print each element in a new line in the same order as the input.
Note:- <b>Print float round off to two decimal places and double to 4 decimal places.</b>Sample Input:-
2
2312351235
1.21
543.1321
c
Sample Output:-
2
2312351235
1.21
543.1321
c, I have written this Solution Code: a=int(input())
b=int(input())
x=float(input())
g = "{:.2f}".format(x)
d=float(input())
e = "{:.4f}".format(d)
u=input()
print(a)
print(b)
print(g)
print(e)
print(u), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: N = int(input())
if N > 5:
print("Greater than 5")
elif(N == 1):
print("one")
elif(N == 2):
print("two")
elif(N == 3):
print("three")
elif(N == 4):
print("four")
elif(N == 5):
print("five"), In this Programming Language: Python, Now tell me if this Code is compilable or not? | Compilable |
For this Question: Given an integer n , your task is to print the lowercase English word corresponding to the number if it is <=5 else print "Greater than 5".
Numbers <=5 and their corresponding words :
1 = one
2 = two
3 = three
4 = four
5 = fiveThe input contains a single integer N.
Constraint:
1 <= n <= 100Print a string consisting of the lowercase English word corresponding to the number if it is <=5 else print the string "Greater than 5"Sample Input:
4
Sample Output
four
Sample Input:
6
Sample Output:
Greater than 5, I have written this Solution Code: import java.util.Scanner;
class Main {
public static void main (String[] args)
{
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
int side = scanner.nextInt();
String area = conditional(side);
System.out.println(area);
}static String conditional(int n){
if(n==1){return "one";}
else if(n==2){return "two";}
else if(n==3){return "three";}
else if(n==4){return "four";}
else if(n==5){return "five";}
else{
return "Greater than 5";}
}}, In this Programming Language: Java, Now tell me if this Code is compilable or not? | Compilable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.