Hello good people, Happy new year.
I was trying to solve a problem, logically I solved it and implemented it in Java. I use eclipse IDE to write and test Java program.
I ran the program and it worked fine, giving the expected answer for different testcases.
But when I submit my solution to codeforces(a competitive programming website), I get runtime error on test 1.
Codeforces judge uses Java SE 17.
java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextLong(Scanner.java:2373)
at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
at Main.solve(Main.java:9)
at Main.main(Main.java:24)
Input
4
2
3
50
1000000000
I was trying to find out from yesterday and submitted more than 10 times with little little changing.. but nothing worked.
So, anyone here to help me?
What I have tried:
import java.util.Scanner;
public class Main {
Scanner sc = new Scanner(System.in);
void solve() {
long n = sc.nextLong();
long mod = 1000000007L;
long ans=((((n*(n+1))%mod)*(4*n-1))%mod*(2022/6))%mod;
System.out.println(ans);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Main main = new Main();
int t = sc.nextInt();
while(t-->0) {
main.solve();
}
}
}