/*
Shahadat Hossain
I.C.T Department
Comilla University
Session: 2013-2014
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define modulo 1000000007
#define inverse 500000004 // modInverse(2)
ll bigMultiple(ll n, ll p){
if(p == 0)
return 0;
else if(p%2 == 1){
ll x = bigMultiple(n, p - 1);
x %= modulo;
ll y = n%modulo;
return (x+y)%modulo;
}
else{
ll x = bigMultiple(n, p/2);
x %= modulo;
return (x+x)%modulo;
}
}
ll sum(ll n){
ll temp;
temp = bigMultiple(n, n+1); // গুন না করে bigMultiple করেছি, এটা মূলত গুণ করতেছেে
temp = bigMultiple(temp, inverse); // ২ এর মড্যুলার ইনভার্স বের করে গুণ করতেছি
return temp;
}
ll fun(ll n, ll mod){
ll temp = sum(mod-1);
ll t2 = n/mod;
t2 = bigMultiple(t2, temp);
ll t3 = n%mod;
t3 = sum(t3);
return (t2+t3)%modulo;
}
int main(){
ll a, b, mod;
scanf("%lld %lld %lld", &a, &b, &mod);
a = fun(a - 1, mod);
b = fun(b, mod);
ll res = b - a;
if(res < 0)
res += modulo;
printf("%lld\n", res);
}
LyoKIFNoYWhhZGF0IEhvc3NhaW4KIEkuQy5UIERlcGFydG1lbnQKIENvbWlsbGEgVW5pdmVyc2l0eQogU2Vzc2lvbjogMjAxMy0yMDE0CiAqLwoKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CgojZGVmaW5lIG1vZHVsbyAxMDAwMDAwMDA3CiNkZWZpbmUgaW52ZXJzZSA1MDAwMDAwMDQgLy8gbW9kSW52ZXJzZSgyKQoKbGwgYmlnTXVsdGlwbGUobGwgbiwgbGwgcCl7CiAgICBpZihwID09IDApCiAgICAgICAgcmV0dXJuIDA7CiAgICBlbHNlIGlmKHAlMiA9PSAxKXsKICAgICAgICBsbCB4ID0gYmlnTXVsdGlwbGUobiwgcCAtIDEpOwogICAgICAgIHggJT0gbW9k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