#include<stdio.h>
main()
{
long int t;
long long int n,x;
scanf("%ld",&t);
while(t--)
{
scanf("%lld",&n);
if(n==1)
printf("20\n");
else if(n==2)
printf("36\n");
else if(n==3)
printf("51\n");
else
{
if(n%4==0)
{
x=n/4;
printf("%d\n",44*x+16);
}
else if((n-1)%4==0)
{
x=(n-1)/4;
printf("%d\n",44*x+32);
}
else if((n-2)%4==0)
{
x=(n-2)/4;
printf("%d\n",44*x+44);
}
else
{
x=(n-3)/4;
printf("%d\n",44*x+55);
}
}
}
}
How Many Test Cases You Are Passing??
EDIT: I HAVE SEEN YOU ARE GETTING 45 PTS
Answer In C++
#include <iostream>
using namespace std;
int main() {
// your code goes here
long long int t;
cin>>t;
while(t--){
long long int n;
cin >> n;
long long int x=n%4;
long long int y=n/4;
long long int a2=0,b3=0,c4=0,d5=0,e=0,f=0;
switch(x){
case 1: d5=1; break;
case 2: c4=2; break;
case 3: c4=2; b3=1; break;
}
if(y>0){
a2+=y*4;
f=(4-x)*4;
}
long long int sum=(a2*11)+(b3*15)+(c4*18)+(d5*20)+f;
cout<<sum<<endl;
}
return 0;
}
Answer In Java
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// Code In Java
long t;
Scanner scin = new Scanner(System.in);
t = scin.nextLong();
while (t-->0){
long n;
n = scin.nextLong();
int x = (int) (n%4);
long y = n/4;
long a2=0,b3=0,c4=0,d5=0,e=0,f=0;
switch (x){
case 1: d5=1; break;
case 2: c4=2; break;
case 3: c4=2; b3=1; break;
}
if(y>0){
a2+=y*4;
f=(4-x)*4;
}
long sum = (a2*11)+(b3*15)+(c4*18)+(d5*20)+f;
System.out.println(sum);
//Code In C++
/*
long long int t;
cin>>t;
while(t--){
long long int n;
cin >> n;
long long int x=n%4;
long long int y=n/4;
long long int a2=0,b3=0,c4=0,d5=0,e=0,f=0;
switch(x){
case 1: d5=1; break;
case 2: c4=2; break;
case 3: c4=2; b3=1; break;
}
if(y>0){
a2+=y*4;
f=(4-x)*4;
}
long long int sum=(a2*11)+(b3*15)+(c4*18)+(d5*20)+f;
cout<<sum<<endl;
*/
}
}
}
Links
Java: CodeChef: Practical coding for everyone
C++: CodeChef: Practical coding for everyone
My All Answers: CodeChef: Practical coding for everyone
your code is correct but actually i’m asking for my mistake .My code solve first 3 constraints but not the fourth one .I’m looking for that answer actually .Why fourth is wrong?
@dark_lord123 - Your code is right. Just one silly mistake you made.
Just change the print from ‘%d’ to ‘%lld’. As the constraints are 10^12.
It will pass through.
See the following link - https://www.codechef.com/viewsolution/45023866
Your Mistake: Just change the print
from ‘%d’ to ‘%lld’
. As the constraints are 10^12