题目大意:给出一个整数,问吧这个整数分成任意多个正整数只和的最大乘积是多少。
思路:根据小学奥数的基本知识,我们要吧这个数字分成尽量多个3。然后这个题就解决了。
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; struct BigInt{ int num[10010],len; BigInt(int _ = 0) { memset(num,0,sizeof(num)); num[len = 1] = _; } BigInt operator *(int a)const { BigInt re; re.len = len; int temp = 0; for(int i = 1; i <= len; ++i) { re.num[i] = num[i] * a + temp; temp = re.num[i] / 10; re.num[i] %= 10; } while(temp) re.num[++re.len] = temp % 10,temp /= 10; return re; } }; int n; int main() { cin >> n; BigInt ans(1); if(n % 3 == 0) for(int i = 1; i <= n / 3; ++i) ans = ans * 3; else if(n % 3 == 1) { for(int i = 1; i <= (n - 1) / 3 - 1; ++i) ans = ans * 3; ans = ans * 4; } else { for(int i = 1; i <= (n - 1) / 3; ++i) ans = ans * 3; ans = ans * 2; } cout << ans.len << endl; for(int i = ans.len,T = 1; T <= min(100,ans.len); ++T,--i) printf("%d",ans.num[i]); return 0; }
原文地址:http://blog.csdn.net/jiangyuze831/article/details/43602591