跳到正文

题解

题解:AT_pakencamp_2020_day1_l のびたす

Ryan_Adam约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年11月13日
收录
2026年11月13日
更新
2026年11月22日
篇幅
约 2 分钟

版本

  1. v1当前

题解:AT_pakencamp_2020_day1_l のびたす

分析

唐题,披着数学标签的模拟题。

洛谷没给数据范围,观察原题中 n≤105n\le 10^5,而题面递推式子都给你了,幂次可以用快速幂解决,唯一生僻一点的是 log⁡10ai\log_{10} a_i,可以用内置函数 log10 解决,其余按式子递推即可,复杂度 O(nlog⁡n)\mathcal{O(n\log n)}。

唯一需要注意一下的是 log10 函数返回值为 double,记得转回 int。

代码

虽然觉得没啥必要贴了,但还是形式化的贴一下吧。

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
const int p=1e9+7;
int a[N];

int qpow(int a,int b)
{
    int res=1;
    for(;b;b>>=1)
    {
        if(b&1)(res*=a)%=p;
        (a*=a)%=p;
    }
    return res%p;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,f;
    cin>>n>>f;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        f=((qpow(10,floor((int)log10(a[i])+1))+1)*f%p+(qpow(2,i))%p*a[i]%p)%p;
    cout<<f<<endl;
    return 0;
}
原文