这道题和之前的2247, 1338是一样的。唯一注意的地方是数据范围更大,不能用int了,用unsigned long long即可。
thestoryofsnow | 2545 | Accepted | 160K | 0MS | C++ | 879B |
/*
ID: thestor1
LANG: C++
TASK: poj2545
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cassert>using namespace std;int main()
{int primes[3], n;scanf("%d%d%d%d", &primes[0], &primes[1], &primes[2], &n);std::vector<unsigned long long> nums(n + 1, 1);int ptr[3] = {0};for (int i = 1; i <= n; ++i){unsigned long long num = nums[ptr[0]] * primes[0];for (int j = 1; j < 3; ++j){num = min(num, nums[ptr[j]] * primes[j]);}nums[i] = num;for (int j = 0; j < 3; ++j){if (nums[ptr[j]] * primes[j] == num){ptr[j]++;}}}printf("%lld\n", nums[n]);return 0;
}