T1
Then do not, there could get the points, mind! ! status! ! T2 equation to consider a push T3 can not discard the wrong question! !
It can be said that three of the original title
T1 Joseph problems
f[i]=(f[i-1]+m)%i cout<<f[n]+1;
Here you can play table to find the law mathematically optimized to $ log $ level
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 int m,n; 8 int main(){ 9 int T; 10 for(cin>>T;T;T--){ 11 scanf("%d%d",&n,&m); 12 int id=0; 13 if(n>m){ 14 for(int i=1;i<=m;i++) 15 id=(id+m)%i; 16 for(int i=m+1;i<=n;i++){ 17 id=(id+m)%i; 18 int jumpl=(i-id)/(m-1); 19 if(i+jumpl<=n){ 20 id=(id+jumpl*m)%(i+jumpl); 21 i+=jumpl; 22 } 23 else{ 24 id=id+(n-i)*m; 25 break; 26 } 27 } 28 }else{ 29 id=0; 30 for(int i=1;i<=n;i++) 31 id=(id+m)%i; 32 } 33 printf("%d\n",id+1); 34 } 35 }
T2 "Fenwick tree."
T3 "linear DP" "longest common subsequence rise."
This problem is lyd Uehara P264
Dp combination of the two is really God