#include using namespace std; int main(){ int64_t N,M,T,a=0,i;cin>>N>>M; vectorF(5e6,1),R(N,0); if(M<3){ cout<<(N==1?2:0); return 0; } if(N==1){ cout<<(M-1)*(M-2)/2+3; return 0; } for(i=1;F[i]!=0||F[i+1]!=1;T=++i)F[i+2]=(F[i+1]+F[i])%N; for(i=1,F[0]=0;i<=T;i++)R[(F[i+2]-1+N)%N]+=((M-2)/T)+(i<=(M-2)%T?1:0); for(i=0,R[0]++;i