#include <iostream>#include <cmath>
using namespace std;
int main(){ int D, day = 0, s = 0; cin >> D; while (s != D){ day++; s = s + day * pow(-1, day + 1); } cout << day; return 0;}
s = s + day * pow(-1, day + 1);
1. pow很慢,不要用
2. pow改掉後雖然能AC (0.7s),但還是慢,其實答案是有規律的,不需要用到迴圈,你再觀察看看