int maxPrime = scanner.nextInt(); // not working for the large dataset The reason it isn't working is because when you ask for scanner.nextInt(), you're saying "Java, please take the next chunk of text, interpret it as a number, and store that number in the 32-bit 'int' type."
The 32-bit 'int' type can handle numbers between -2^31 and 2^31 - 1, which is about -2 billion to 2 billion. It can't handle hundred-digit numbers like the ones in this problem. For a lot of problems, you can make things better by using the 'long' type instead of the 'int' type. That can handle numbers between -2^63 and 2^63-1, which is about -9*10^18 to 9*10^18. Still not enough for the big numbers in this problem. For this problem, you want Java's BigInteger class. BigInteger maxPrime = scanner.nextBigInteger(); BigInteger can handle essentially arbitrary numbers (It probably couldn't handle a number whose decimal representation can't fit in RAM, but that isn't your problem here). You'll have to look up the API to see how to use it. Good luck! Bartholomew -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAHaiWHM%2B6oPj%2BZbdV4%3D8%2BeVPP7OUxf1w-ZQO6sfT-mUF0n3d1Q%40mail.gmail.com.