sgu 118 Digital Root

题意:算式中结果的数字根。

先取两数的数字根再乘起来,和先乘起来再取数字根结果一样。因此化简式子。

#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;
}

 

转载于:https://www.cnblogs.com/gaudar/p/9761613.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值