/* Name of the class has to be “Main” only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t,n ;
t = sc.nextInt();
int i;
while(t-->0)
{
n = sc.nextInt();
int c = 1;
while(n!=1){
for(i=n-1;i>=1;i--)
{
if(n%i==0)
{
c++;
n = n - i;
break;
}
}
}
if(c%2==0){
System.out.println("ROHIT");
}
else{
System.out.println("VISHAL");
}
}
}
}
how do i solve this?
it works fine on ideone but while submitting on codechef i get this runtime error…
Please help me…
public static void main(String[] args)
{
int c=calculate();
System.out.println(c);
}
public static int calculate()
{
int count=0;
Scanner inp=new Scanner(System.in);
System.out.println("Enter No. of time input take:\t ");
int n=inp.nextByte();
int a[]=new int[n];
System.out.println("All input must be divisible \t "); //k<10pow7
int k=inp.nextByte();
System.out.println("Enter values:");
for(int i=0;i<n;i++) {
a[i] = inp.nextInt();
if (a[i] % k == 0)
count++;
}
return count;
}
I was solving this problem SUMTRIAN( SUMTRIAN Problem - CodeChef ) and was getting this error with Python. I was getting input using raw_input() which was coupled with split(’ ') to get a list. This is how I was taking input and converting it into a list of integers : lst = map(int, list(raw_input().split(’ ')))
Solution to this error:
Change the code to : lst = map(int, list(raw_input().strip().split(’ ')))
strip() removes any unnecessary blank spaces in the input and this removed the NZEC error.
My code is executing fine on my laptop but give NZEC error on codechef .Please can anyone tell me what’s wrong with it.
import java.util.Scanner;
public class Main {
static int max, p;
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
long n = inp.nextInt();
int A[] = new int[1000];
int B[] = new int[1000];
int i, j;
int lead;
for (i = 0; i < n; i++) {
A[i] = inp.nextInt();
B[i] = inp.nextInt();
}
for (i = 0; i < n; i++) {
if (A[i] > B[i]) {
lead = A[i] - B[i];
if (lead > max) {
max= lead;
p = 1;
}
}
else {
lead = B[i] - A[i];
if (lead > max) {
max = lead;
p = 2;
}
}
}
System.out.println(p+ " " + max);
}
my code is running fine in my laptop but getting nzec in codechef . iam using java and i have used bufferedreader class and scanner class both but iam still getting nzec in both cases
@codehardy can you please mention for which question you have write this code as you have created array A and B of size 1000 elements , which may be insufficient according to the constraints of the question.
https://www.codechef.com/viewsolution/20963272
This is solution of a question ,it is running perfectly on my laptop but giving an NZEC error on codechef.
Anyone please help.Help me in knowing my mistakes.