题解 | #小易的升级之路#
小易的升级之路
https://www.nowcoder.com/practice/fe6c73cb899c4fe1bdd773f8d3b42c3d
#include<iostream> #include <type_traits> #include<vector> using namespace std; //辗转相除法 int GCD(int a,int b) { int c; while(c=a%b) { a=b; b=c; } return b; } int GetPowerValue(int n,int power) { vector<int> num(n); //防御值 for(int i=0;i<n;++i) { cin>>num[i]; } for(int i=0;i<n;++i) { if(power>num[i]) power+=num[i]; else power+=GCD(power,num[i]); } return power; } int main() { int n,a,power; while(cin>>n>>a) { power=GetPowerValue(n,a); cout<<power<<endl; } }