标签:cto res break ++ cas clu 题意 class ble
题意:算式中结果的数字根。
先取两数的数字根再乘起来,和先乘起来再取数字根结果一样。因此化简式子。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> using namespace std; const double EPS=1e-8; const int SZ=10030,INF=0x7FFFFFFF; typedef long long lon; lon work(lon x) { lon res=0; for(;x;) { res+=x%10; x/=10; } return res<10?res:work(res); } int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; cin>>casenum; for(lon time=1;time<=casenum;++time) { lon n; cin>>n; vector<lon> vct(n); for(lon i=0;i<n;++i) { cin>>vct[i]; } lon cur=1; for(lon i=vct.size()-1;i>=0;--i) { cur*=vct[i]; cur=work(cur); if(i==0)break; cur+=1; } cout<<cur<<endl; } return 0; }
标签:cto res break ++ cas clu 题意 class ble
原文地址:https://www.cnblogs.com/gaudar/p/9761613.html