标签:style blog color io ar for 2014 div cti
/******************************************************************** @file Main_practise.cpp @date 2014-8-29 @author Tiger @brief The 3n + 1 problem ********************************************************************/ #include <cstdio> #include <algorithm> const int SIZE = 1000000; __int64 Records[SIZE]; void Cal3NPlus1(void); int main(int argc, const char* argv[]) { Cal3NPlus1(); int nA = 0, nB = 0; while (scanf("%d%d", &nA, &nB) != EOF) { int nMax = std::max(nA, nB); int nMin = std::min(nA, nB); __int64 nSum = 0; for (int i=nMin; i<=nMax; ++i) { nSum < Records[i] ? nSum = Records[i] : nSum; } printf("%d %d %d\n", nA, nB, nSum); } return 0; } void Cal3NPlus1(void) { for (__int64 i=1; i<SIZE; ++i) { __int64 j = i, nCnt = 0; while (j != 1) { if ((j & 1) == 1) { j = 3*j + 1; } else { j /= 2; } ++nCnt; } Records[i] = ++nCnt; } }
标签:style blog color io ar for 2014 div cti
原文地址:http://www.cnblogs.com/roronoa-zoro-zrh/p/3944136.html