#include<iostream> using namespace std; int main(){ int arr[46]; int dp[1001] = { 0, }; for(int i = 1; i<45; i++){ arr[i] = (i*(i+1))/2; } for(int i = 1; i<45; i++){ for(int j = 1; j<45 && arr[i] + arr[j] <= 1000; j++){ for(int k = 1;arr[i] + arr[j] + arr[k] <=1000 && k<45; k++){ dp[arr[i] + arr[j] + arr[k]] = 1; } } } int N; cin>> N; for(int i = 0; i<N; i++){ int tmp; cin>> tmp; cout<< dp[tmp] <<endl; } }
#include <iostream> int a[50] = { 0, }; int check(int n) { for (int i = 1; a[i] <= n; i++) { for (int j = i; a[j] <= n - a[i]; j++) { for (int k = j; a[k] <= n - a[i] - a[j]; k++) { if (a[i] + a[j] + a[k] == n) return 1; } } } return 0; } int main() { int t; for (int i = 0, j = 0; j < 1000; i++, j += i) a[i] = j; std::cin >> t; while (t--) { int n; std::cin >> n; std::cout << check(n) << std::endl; } return 0; }