Can anyone find what’s wrong in this code I tried for every possible test case but after submission it gives WA for large numbers
#define ll long long
using namespace std;
Type casting a 64 bit integer into a float can cause problems. Use
Generally, never use floating point arithmetic when integer answers are expected.
Integer division of a/b in C++ is equivalent to floor(a/b)
Thanks … now it’s correct
can you please help me with this code
it got wa.
I don’t know about the rest, but you Cannot divide by 2 directly when you are doing modular arithmetic. This line
thank you .
should i use modular multiplicative inverse?
Probably. If you still get wrong answer I’ll check the rest of the code.
still getting wrong answer!
n is an
int up to 10^9 so
ans=(n*n)%p; will overflow. Remember when you multiply 2
ints the answer is still an int, even if you assign it to a
long long or take mod p afterwards. I would recommend rewriting the code and please use something like
const int p= 1000000007 and take mod p. Your code is very ugly, and it’s hard to debug ugly codes.
thank you very much .
changed int to long long and it got accepted.