4
My code is like this:
#include <stdio.h>
int main()
{
unsigned long int L, N;
scanf("%lu%lu", &L, &N);
printf("%lu\n", (L-(N-1))*(L-(N-1)) + (N-1));
return 0;
}
When the test case has low numbers, the program works. However, when the numbers are beyond the capacity of the unsigned long int
, with entries like 1,000,000 and 9 (the correct answer would be 999984000072) the program gives the wrong answer.
How can I operate with larger integers?
or ... cheat:
sprintf(cmd, "echo 'n=%lu; l=%lu; print (l-(n-1))*(l-(n-1))+(n-1)' | python", n, l); system(cmd);
– pmg
Oh! Just one more thing. The conversation strings for
unsigned long long
use%llu
in both printf and scanf.– pmg