#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- ll L,R,M; ll mo; map enumpr(ll n) { map V; for(ll i=2;i*i<=n;i++) while(n%i==0) V[i]++,n/=i; if(n>1) V[n]++; return V; } ll ext_gcd(ll p,ll q,ll& x, ll& y) { // get px+qy=gcd(p,q) if(q==0) return x=1,y=0,p; ll g=ext_gcd(q,p%q,y,x); y-=p/q*x; return g; } pair crt(ll a1,ll mo1,ll a2,ll mo2) { // return (x,y) y=lcm(a1,a2),x%mo1=a1,x%mo2=a2 ll g,x,y,z; g=ext_gcd(mo1,mo2,x,y); a1=(a1%mo1+mo1)%mo1;a2=(a2%mo2+mo2)%mo2; if(a1%g != a2%g) return pair(-1,0); // N/A __int128_t lcm=mo1*(mo2/g); if(lcm(-2,0); // overflow __int128_t v=a1+((a2-a1)%lcm+lcm)*x%lcm*(mo1/g); return make_pair(((v%lcm)+lcm) % lcm,lcm); } ll lucas_ex(ll n,ll r,ll p,ll q) { // C(n,r) % p^q const int NUM_=400001; static ll fact[NUM_+1], pp, pq; if(n<0||r<0||r>n) return 0; ll P=1; int i; ll k=n-r; FOR(i,q) P*=p; ll mo=P; ll e0=0,eq1=0; if (fact[0]==0 || p!=pp || q!=pq) { pp=p; pq=q; fact[0]=1; for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo; } for(ll v=n/p;v;v/=p) e0+=v%p; for(ll v=r/p;v;v/=p) e0-=v%p; for(ll v=k/p;v;v/=p) e0-=v%p; for(ll v=n/P;v;v/=p) eq1+=v%p; for(ll v=r/P;v;v/=p) eq1-=v%p; for(ll v=k/P;v;v/=p) eq1-=v%p; ll a=1,b=1; while(n) { a=a*fact[n%p]%P; b=b*fact[r%p]%P*fact[k%p]%P; n/=p; r/=p; k/=p; } ll s,t; ext_gcd(b,P,s,t); ll ret=a*(P+s)%mo; FOR(i,e0) ret=ret*p%mo; if(p>2||q<=2) ret=(mo-ret)%mo; return ret; } ll ret[101010]; void solve() { int i,j,k,l,r,x,y; string s; cin>>L>>R>>M; auto m=enumpr(M); R++; ll pmo=1; FORR2(a,b,m) { mo=1; FOR(i,b) mo*=a; FOR(i,R-L) { ll v=lucas_ex(2*(L+i),L+i,a,b); auto p=crt(ret[i],pmo,v,mo); ret[i]=p.first; } pmo*=mo; } ll sum=0; FOR(i,R-L) sum+=ret[i]+M-2; cout<