#include #include #include #include #define REP(i,a,b) for(i=a;i>1])for(j=(i*i)>>1;j>32; if(xh) res -= 32, xl = xh; if(xl&0xffff0000U) res -= 16, xl >>= 16; if(xl&0x0000ff00U) res -= 8, xl >>= 8; return res + ullNumberOfLeadingZerosTable[xl]; } ull ullMultipleMod(ull x, ull y, ull m){ int k,loop=2; ull xlo,xhi,ylo,yhi,rlo,rhi,d1,d2,a,r,mask=0xffffffffULL; if(m<=mask) return (x*y)%m; xlo=(x&mask); xhi=(x>>32); ylo=(y&mask); yhi=(y>>32); rhi=xhi*yhi; rlo=xlo*ylo; a=(rlo>>32)+xhi*ylo; rhi+=(a>>32); a&=mask; a+=xlo*yhi; rhi+=(a>>32); rlo = (rlo&mask) | ((a&mask)<<32); k = ullNumberOfLeadingZeros(m); rhi = (rhi<>(64-k)); rlo<<=k; m<<=k; d1=(m>>32); d2=(m&mask); while(loop--){ r = rhi/d1*d2; rhi = ( (rhi%d1 << 32) | (rlo>>32) ); rlo = ( (rlo&mask) << 32 ); if(rhim) rhi+=m; } return rhi>>k; } /* (x^k)%m */ ull ullPowMod(ull x, ull k, ull m){ ull res; if(k==0) return 1; res = ullPowMod(x,k/2,m); res = ullMultipleMod(res,res,m); if(k%2) res = ullMultipleMod(res,x,m); return res; } /* memo for cal_ord */ int cal_ord_memo[100000]; ll last_n, last_ord; /* return ord_2(n) */ /* phi = phi(n) */ ll cal_ord_2(ll n, ll phi){ int i; ll res = phi, t = phi; if(n == last_n) return last_ord; if(n < 100000 && cal_ord_memo[n] >= 0) return cal_ord_memo[n]; rep(i,ps){ if(p2[i] > t) break; if(t%p[i]) continue; while(t%p[i]==0) t/=p[i]; while(res%p[i]==0 && ullPowMod(2,res/p[i],n)==1) res/=p[i]; } if(t > 1){ while(res%t==0 && ullPowMod(2,res/t,n)==1) res /= t; } last_n = n; last_ord = res; if(n < 100000) cal_ord_memo[n] = res; return res; } /* now[k-L] = k */ /* now_factor, now_facnum, now_facsize denote the factors of now[k] */ ll now[51000]; ll now_factor[51000][15]; int now_facnum[51000][15], now_facsize[51000]; ll res[51000]; /* # of words lendth k = 26^res[k-L] */ void solve(int ind, int depth, ll fac[], int facnum[], int facsize){ int i,j; ll n, phi, ord; if(depth == now_facsize[ind]){ if(facsize==0){ res[ind]++; return; } n = phi = 1; rep(i,facsize){ phi *= fac[i]-1; REP(j,1,facnum[i]) phi *= fac[i]; rep(j,facnum[i]) n *= fac[i]; } /* ord_2(n) = LCM(ord_2(fac[i]^facnum[i]) */ ord = 1; rep(i,facsize){ ll send_n = 1, send_phi = 1, tmp; send_phi *= fac[i]-1; REP(j,1,facnum[i]) send_phi *= fac[i]; rep(j,facnum[i]) send_n *= fac[i]; tmp = cal_ord_2(send_n,send_phi); ord = LCM(ord, tmp); } /* printf("n = %lld, phi = %lld, ord = %lld\n",n,phi,ord);*/ res[ind] += phi / ord; return; } /* bruteforce for searching divisors of now[ind] */ solve(ind, depth+1, fac, facnum, facsize); REP(i, 1, now_facnum[ind][depth]+1){ fac[facsize] = now_factor[ind][depth]; facnum[facsize] = i; solve(ind, depth+1, fac, facnum, facsize+1); } } int main(){ ll i,k; int T; ll L, R, wid; ll out; ll fac[15]; int facnum[15]; rep(i,100000) cal_ord_memo[i] = -1; last_n = -1; ps = getPrime(100000, p); rep(i,ps) p2[i] = p[i]*(ll)p[i]; scanf("%d",&T); while(T--){ scanf("%lld%lld",&L,&R); while(L <= 6915878970LL && 6915878970LL <= R); while(L <= 9704539845LL && 9704539845LL <= R); while(L <= 3486784401LL && 3486784401LL <= R); wid = R - L + 2; rep(i,wid) now[i] = L+i, now_facsize[i] = 0; /* factorize now[i] */ rep(i,ps){ k = L/p[i]*p[i]; while(k 1){ now_factor[i][now_facsize[i]] = now[i]; now_facnum[i][now_facsize[i]] = 1; now_facsize[i]++; } rep(i,wid) now[i] = L+i; /* end of factorize now[i] */ /* rep(i,wid){ printf("%lld = ",now[i]); rep(j,now_facsize[i]){ if(j) printf(" * "); printf("%lld^%d",now_factor[i][j],now_facnum[i][j]); } puts(""); } */ rep(i,wid) if(now[i] % 2 == 1){ res[i] = 0; solve(i, 0, fac, facnum, 0); } rep(i,wid-1) if(now[i] % 2 == 0){ res[i] = res[i+1] - 1; } out = 0; REP(i,L,R+1) out += ullPowMod(26, res[i-L], M); out %= M; printf("%d\n",(int)out); } return 0; }