/******************************************************************** @file Main_practise.cpp @date 2014-9-11 @author Tiger @brief 验证角谷猜想 ********************************************************************/ #include <cstdio> void print(int nNum, bool& bFirst); int main(int argc, const char* argv[]) { int nTestCases = 0; scanf("%d", &nTestCases); while (nTestCases--) { int nNum = 0; scanf("%d", &nNum); int nCnt = 0; bool bFirst = true; while (nNum != 1) { if ((nNum & 1) == 1) { print(nNum, bFirst); nNum = nNum*3 + 1; ++nCnt; } else { nNum /= 2; } } if (0 == nCnt) { printf("No number can be output !\n"); } else { printf("\n"); } } return 0; } void print(int nNum, bool& bFirst) { if (bFirst) { printf("%d", nNum); bFirst = false; } else { printf(" %d", nNum); } }
时间: 2024-10-17 23:16:23