|
|
вернуться в форум1209. 1, 10, 100, 1000... - WA on #5 If the input is P then the output will be 1 if P can be expressed as 1+(n(n-1)/2) => 1+(n(n-1)/2) = p => 2+n(n-1) = 2p => n(n-1) = 2p-2 To find such n I used floor and ceil of sqrt(2p-2) What's wrong with my logic? #include <bits/stdc++.h> using namespace std; int main(){ double n, k, a, b, root; vector<int> v; cin >> k; while(k--){ cin >> n; root = sqrt((2*n) - 2); a = ceil(root); b = floor(root); if(a == root && b == root){ v.push_back(0); }else{ if(a * b == (2*n) - 2) v.push_back(1); else v.push_back(0); } } for (int i = 0; i < v.size(); ++i){ if(i == v.size() - 1) cout << v[i]; else cout << v[i] << " "; } return 0; } Edited by author 30.08.2016 20:42 |
|
|