You must use mathematical solution otherwise You May be **Out of Memory** or **Out of Time**. Here is my **Out Of Time** Solution. I have no idea how to fix it. Anyone can help me?

```
class Solution {
public:
bool canWinNim(int n) {
bool a[3];
for(int i=0;i<3;i++) a[i] = true;
for(int i=3;i<n;i++){
a[i%3] = !(a[(i-1)%3]&&a[(i-2)%3]&&a[(i-3)%3]);
};
return a[(n-1)%3];
}
};
```