目录
牛客WY3 小易的升级之路
解析代码
牛客WY3 小易的升级之路
小易的升级之路_牛客题霸_牛客网
解析代码
#include <iostream>
#include <vector>
using namespace std;int getVal(int a, int b)
{if (a > b)swap(a, b);for (int i = a; i >= 1; --i){if (a % i == 0 && b % i == 0)return i;}return -1;
}int main()
{int n = 0, c = 0;while (cin >> n >> c){vector<int> arr(n);for (int i = 0; i < n; ++i){cin >> arr[i];}for (int i = 0; i < n; ++i){if (arr[i] <= c)c += arr[i];elsec += getVal(c, arr[i]);}cout << c << endl;}return 0;
}