Why did this not work for the problem ONE23 in FULU20

```
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
void solve();
signed main()
{
int t = 1;
// cin >> t;
while(t--)
solve();
}
void solve()
{
int n;
cin >> n;
cout << (n + n*n + n*n*n)%mod;
}
```

@jains8844

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

See the macros

He define int as long long.

1 Like

why the above approach fails?

you have to take modulus seperately for n, n*n, n*n*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 ?