WA in ONE23

Why did this not work for the problem ONE23 in FULU20

using namespace std;
#define int long long
#define mod 1000000007

void solve();
signed main()
    int t = 1;
    // cin >> t;
void solve()
    int n;
    cin >> n;
    cout << (n + n*n + n*n*n)%mod;


bro take n to long long :slight_smile:

no when we cube of no. upto 10^5 it will overflow :slight_smile:

See the macros
He define int as long long.

1 Like

q .link : CodeChef: Practical coding for everyone

why the above approach fails?

you have to take modulus seperately for n, nn, nn*n and then take final modulus

but why ?
if i take max n = 10^5
then n*n = 10^10
n * n * n = 10^15
10^5+10^10+10^15 = 1000010000100000
1000010000100000 < 10^18 (upper limit of long long)
then why it is wrong?

read this article. solution of your every doubt
link: Modulo 10^9+7 (1000000007) - GeeksforGeeks

Nah bro this article is different here at max the no is less than 10^16 still it gives WA ?