#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <ctime>
#include <deque>
#include <queue>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(a) (a).begin(), (a).end()
void readInt(){} void RI( int &X){ scanf ( "%d" ,&X);} template < typename ...R>
void RI( int &f,R&...r){RI(f);RI(r...);} void RIA( int *p, int *q){ int d=p<q?1:-1;
while (p!=q){ scanf ( "%d" ,p);p+=d;}} void print(){cout<<endl;} template < typename T>
void print( const T t){cout<<t<<endl;} template < typename F, typename ...R>
void print( const F f, const R...r){cout<<f<< ", " ;print(r...);} template < typename T>
void print(T*p, T*q){ int d=p<q?1:-1; while (p!=q){cout<<*p<< ", " ;p+=d;}cout<<endl;}
typedef pair< int , int > pii;
typedef long long ll;
typedef unsigned long long ull;
template < typename T> bool umax(T &a, const T &b) {
return a >= b? false : (a = b, true );
}
/* -------------------------------------------- */
vector< int > table;
void init() {
for ( int i = 1; ; i ++) {
ll buf = 3ll * i * (i - 1) + 1;
if (buf > 1e9 + 7) break ;
table.pb(( int )buf);
}
}
bool chk( int x) {
int l = 0, r = upper_bound(all(table), x - table[0]) - table.begin() - 1;
while (l < r && table[l] + table[r] != x) {
l ++;
while (l < r && table[l] + table[r] > x) r --;
}
return table[l] + table[r] == x;
}
int main() {
#ifndef ONLINE_JUDGE
freopen ( "in.txt" , "r" , stdin);
#endif // ONLINE_JUDGE
int T;
cin >> T;
init();
while (T --) {
int x;
RI(x);
if (find(all(table), x) != table.end()) {
puts ( "1" );
continue ;
}
if (chk(x)) {
puts ( "2" );
continue ;
}
for ( int k = 3; ; k ++) {
if ((x - k) % 6 == 0) {
printf ( "%d\n" , k);
break ;
}
}
}
return 0;
}
|