How to improve time in this problem so that it could have been accepted;

```
#include<stdio.h>
int scan(){
int t=0;
char c;
c=getchar_unlocked();
while(c<'0' || c>'9')
c=getchar_unlocked();
while(c>='0' && c<='9'){
t=(t<<3)+(t<<1)+c-'0';
c=getchar_unlocked();
}
return(t);
}
int main(void){
short unsigned M, N, temp, ans[100001], x, y=0;
short unsigned T;
scanf("%hu", &T);
temp=T;
//for(temp=0; temp<T; temp++){
while(T){
M=scan();
N=scan();
for(x=0; x<M; x++)
y = y + (x*N)/M;
ans[temp]=2*y;
T--;
}
//for(temp=0; temp<T; temp++)
while(temp){
printf("\n%hu", ans[temp]);
temp--;
}
return 0;
}
```