思路:打表找规律,赛时没找出来。但是还是要水个博客。
开头6个数分别是6组等差数列的开头,每组等差数列的两项之间间隔6个数。
1 5 9 13
1 4 7 10
0 1 2 3
3 9 15 21
0 1 2 3
3 6 9 12
开头 1 1 0 3 0 3是前6项
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
typedef long long ll;
int main() {
int T;
ios::sync_with_stdio(0);
cin >> T;
while(T--) {
ll n;
cin >> n;
ll ans;
ll t = n % 6 , cnt = n / 6;
if(t == 0) {
ans = cnt * 3;
}
else if(t == 1) {
ans = 1 + cnt * 4;
}
else if(t == 2) {
ans = 1 + cnt * 3;
}
else if(t == 3) {
ans = cnt;
}
else if(t == 4) {
ans = 3 + cnt * 6;
}
else ans = cnt;
cout << ans << "\n";
}
return 0;
}