Enormous input test

using namespace std;
int main()
{unsigned long n,k,t;
int i = 0;
int count = 0;
while(i < n)
if (t%k==0)

Why is this giving wrong answer?

One of the reasons could be that you are incrementing the variable “i” inside the if block…I think it should be outside…hope this helps…:slight_smile:

Other two reasons are:

  1. Not printing new line

  2. Additional comma in the scanf’s format specifier

no new line required!!!

maybe the data type n is of unsigned long you are using and in the loop you are incrementing i and checking it with n which might be upto 10^7 . so try changing the data type of i and count from int to unsigned long and

The problem is in this line


It should be

scanf("%lu %lu",&n,&k);

That is you should separate the %lu with a space and not a comma. It’s also best if you change i and count to unsigned long, just to be safe. Once you change that, your program gives the right output ( well it gave the right output for the conditions that I tried ).

Hope this solves your problem


i++ is not inside the if block, it’s outside of it

oh yaa…sorry…my bad!!!