這是一道比較有趣的數學題。
咱們設結果爲 \(x+1\),爲何 \(+1\) 呢?爲的是後面好計算。這裏加的 \(1\) 是最開始放的那個。
容易看出題意就是從 \(0\) 開始,每次加 \(n+1\) 再對 \(4n\) 取模,直到變成 \(0\) 爲止。問這樣的操做要幾回。因而能夠列出下面這個方程:spa
到這裏好像沒有頭緒了……
能夠想到結果應該是和 \(4\) 有關的,因而咱們能夠分類討論下。code
(因爲題目要求,算出來的都是最小正整數解,因此下面直接用 \(=\) 了QAQ)get
當 \(n \equiv 0 \pmod 4\) 時,顯然數學
因此 \(x \equiv 0 \pmod{4n}\),容易獲得string
當 \(n \equiv 1 \pmod 4\) 時,能夠像上面那樣算出 \(x+x \equiv 0 \pmod{4n}\),因此又能夠獲得it
當 \(n \equiv 2 \pmod 4\) 時,又能夠獲得 \(2x+x \equiv 0 \pmod{4n}\),此時能夠獲得io
顯然題目要讓 \(k\) 儘可能小且結果爲正整數,因此 \(k=3\),因而就能獲得class
當 \(n \equiv 3 \pmod 4\) 時,能夠獲得di
整理一下就是:
\(ans\) 表示題目要求的答案。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; long long T,n; int main() { scanf("%lld",&T); while(T--) { scanf("%lld",&n); switch(n%4) { case 0:printf("%lld\n",4*n+1);break; case 1:printf("%lld\n",2*n+1);break; case 2:printf("%lld\n",4*n+1);break; case 3:printf("%lld\n",n+1);break; } } return 0; }