module mdl implicit none contains logical function assert(flag) logical::flag if(.not.flag)call exit(1) end function function mul(a,b,md) implicit none integer(kind=8)::mul(2,2),a(2,2),b(2,2) integer(kind=8)::md integer::i,j,k do i=1,2 do j=1,2 mul(i,j)=0 end do end do do i=1,2 do j=1,2 do k=1,2 mul(i,j)=mul(i,j)+mod(a(i,k)*b(k,j),md) if(mul(i,j)>=md)mul(i,j)=mul(i,j)-md end do end do end do end function function pow_mat(a,pwr,md) implicit none integer(kind=8)::pow_mat(2,2),dub_mat(2,2),a(2,2) integer(kind=8),value::pwr,md integer::i,j,k do i=1,2 do j=1,2 if(i==j)then pow_mat(i,i)=1 else pow_mat(i,j)=0 end if dub_mat(i,j)=a(i,j) end do end do do while(pwr>0) if(mod(pwr,2)==1)pow_mat=mul(pow_mat,dub_mat,md) dub_mat=mul(dub_mat,dub_mat,md) pwr=pwr/2 end do end function integer(kind=8) function pow(a,pwr,md) implicit none integer(kind=8),value::a,pwr,md pow=1 do while(pwr>0) if(mod(pwr,2)==1)pow=mod(pow*a,md) a=mod(a*a,md) pwr=pwr/2 end do end function integer(kind=8) function fib(n,md) implicit none integer(kind=8)::n,md integer(kind=8)::mat(2,2) mat(1,2)=1 mat(1,1)=0 mat(2,1)=1 mat(2,2)=1 mat=pow_mat(mat,n,md) fib=mat(1,2) end function logical function loopsize(n,md) implicit none integer(kind=8)::n,md loopsize=.false. loopsize=fib(0_8,md)==fib(n,md).and.fib(1_8,md)==fib(n+1,md) end function integer(kind=8) function calc(p) implicit none integer(kind=8),value::p integer::i,j,k if(p==2)then calc=3 else if(p==5)then calc=20 else if(mod(p,5)==1.or.mod(p,5)==4)then calc=f(p-1,p) else if(mod(p,5)==2.or.mod(p,5)==3)then calc=f(2*p+2,p) end if end function integer(kind=8) function f(a,md) implicit none integer(kind=8),value::a,md integer(kind=8)::i,j,k f=a do i=1,a if(mod(a,i)==0)then if(loopsize(i,md))then f=min(f,i) end if if(loopsize(a/i,md))then f=min(f,a/i) end if end if if(i*i>=a)exit end do end function end module program main use mdl implicit none integer(kind=8)::i,j,k,cnt integer(kind=8)::ret=1 integer(kind=8)::n,p(1000),d(1000),idx(20000002),tmp,tmp2 integer(kind=8)::md2 md2=1000000007 read*,n do i=1,size(idx) idx(i)=0 end do do i=1,n read(*,*)p(i),d(i) tmp=calc(p(i)) tmp2=0 do j=2,tmp cnt=0 do while(mod(tmp,j)==0) cnt=cnt+1 tmp=tmp/j end do if(j==p(i))tmp2=cnt idx(j)=max(idx(j),cnt) if(j*j>=tmp)exit end do if(tmp>1)then cnt=1 if(tmp==p(i))tmp2=1 idx(tmp)=max(idx(tmp),cnt) end if idx(p(i))=max(idx(p(i)),tmp2+d(i)-1) end do do i=1,size(idx) ret=ret*pow(i,idx(i),md2) ret=mod(ret,md2) end do print*,ret end program