|
|
back to boardCommon Board1209: 1, 10, 100, 1000... Posted by kema 22 Oct 2006 01:15 what is test 3? this is my program #include <iostream.h> #include <fstream.h> #include <math.h> int i,h,n,k; int main() { cin >> n; for (i=1;i<=n;i++) { cin >> k; h=ceil(sqrt((double)((k-1)*2))); if (h*(h-1)/2 + 1==k) cout << 1 << ' '; else cout << 0 << ' '; } return 0; } dont know why it is wrong answer Re: 1209: 1, 10, 100, 1000... Probably (k - 1) * 2 causes integer overflow, the same is for h * (h - 1) Try (double(k - 1)) * 2 and int(double(h) * (h - 1) / 2 + 1) or something like that. Re: 1209: 1, 10, 100, 1000... Posted by kema 22 Oct 2006 16:01 Many thanks It works well Edited by author 22.10.2006 16:01 Edited by author 22.10.2006 16:02 |
|
|