How to calculate mod involving no.s upto 1e18

I have to calculate summation(n mod i^2) from i=1 to i=m where n and m can both vary up to 1e18.
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
const int mod=1e9+7;
inline ll int add(ll int a,ll int b){a+=b; a%=mod;return a;}
inline ll int mul(ll int a,ll int b){return (a1llb)%mod;}
inline ll int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–){
unsigned long long int n,m;
cin>>n>>m;
unsigned long long int finans=0;
unsigned long long int inc=0;
for(unsigned long long int i=1;i<=m;i++){
inc=(n%(mul(i,i)))%mod;
finans=add(finans,inc);
}
cout<<finans<<"\n";
}
return 0;
}

And this code gives correct answer only upto n=1e5 and m=1e5 (checked from wolfram alpha)

Blockquote

It’s answered on Codeforces!

Thanks