当前位置: 首页 > news >正文

atcoder ABC 357-D题详解

atcoder ABC 357-D题详解

Problem Statement

For a positive integer N, let VN​ be the integer formed by concatenating N exactly N times.
More precisely, consider N as a string, concatenate N copies of it, and treat the result as an integer to get VN​.
For example, V3​=333 and V10​=10101010101010101010.

Find the remainder when VN​ is divided by 998244353.

Constraints

1≤N≤1018
N is an integer.

Input

The input is given from Standard Input in the following format:

N

Output

Print the remainder when VN​ is divided by 998244353.

Sample Input 1

5

Sample Output 1

55555
The remainder when V5​=55555 is divided by 998244353 is 55555.

Sample Input 2

9

Sample Output 2

1755646
The remainder when V9​=999999999 is divided by 998244353 is 1755646.

Sample Input 3

10000000000

Sample Output 3

468086693
Note that the input may not fit into a 32-bit integer type.

思路分析1:

暴力直接写,re和tle

code:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
string s;
vector<string>v;
ll n;
int main(){cin>>s;//s本来就有一个,所以后面要减1ll n=stoll(s);for(ll i=0;i<n-1;i++){v.push_back(s);}for(ll i=0;i<n-1;i++){s=s+v[i];}ll cnt=stoll(s);cnt=cnt%998244353;cout<<cnt;
}

思路分析2:

本题使用快速幂,先拼接,可以发现是等比数列,然后使用等比数列求和公式,因为数太大会爆ll,所以使用欧拉定理和费马小定理分别化简式子来优化时间复杂度,最后答案也要先mod后乘,不然会爆ll。

code:

#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod=998244353;
ll n;
int qpow(int a,int n){//不用欧拉定理应该为ll nint res=1;while(n){if(n&1) res=1ll*res*a%mod;a=1ll*a*a%mod;n>>=1;}return res;
}
int getlen(ll n){int ans=0;while(n){ans++;n/=10;}return ans;
}
int main(){cin>>n;int l=getlen(n);int c1=qpow(10,n%(mod-1)*l%(mod-1))-1;//n*l会爆ll所以要分别先mod//不用欧拉定理c1=qpow(10,qpow(10,l),n)-1;int c2=qpow(10,l)-1;c2=qpow(c2,mod-2);int ans=1ll*n%mod*c1%mod*c2%mod;cout<<ans;return 0;
}
http://www.lryc.cn/news/389280.html

相关文章:

  • 从单一到多元:EasyCVR流媒体视频汇聚技术推动安防监控智能升级
  • Spring MVC数据绑定和响应——数据回写(二)JSON数据的回写
  • 怎么快速给他人分享图片?扫描二维码看图的简单做法
  • 【UML用户指南】-26-对高级行为建模-状态图
  • 解决VSCode无法用ssh连接远程服务器的问题
  • 【区块链+基础设施】银联云区块链服务 | FISCO BCOS应用案例
  • Java SE入门及基础(61) 死锁 死锁发生条件
  • 简单爬虫案例——爬取快手视频
  • 42、nginx之nginx.conf
  • 高薪程序员必修课-java为什么要用并发编程
  • postgreSQL学习
  • 【3】系统标定
  • 网安小贴士(3)网安协议
  • 大数据面试题之HBase(1)
  • git回退commit的方式
  • [Information Sciences 2023]用于假新闻检测的相似性感知多模态提示学习
  • 自定义vue3 hooks
  • 《昇思25天学习打卡营第21天 | 昇思MindSporePix2Pix实现图像转换》
  • 【文档+源码+调试讲解】科研经费管理系统
  • linux 下 rm 为什么要这么写?
  • 【Spring Boot】Spring AOP中的环绕通知
  • docker部署前端,配置域名和ssl
  • 初学Spring之 IOC 控制反转
  • rpc的仅有通信的功能,在网断的情况下,比网通情况下,内存增长会是什么原因
  • 从零开始:如何设计一个现代化聊天系统
  • 香橙派OrangePi AIpro初体验:当小白拿到一块开发板第一时间会做什么?
  • 【C语言内存函数】
  • Mysql部署MHA高可用
  • 【算法学习】射线法判断点在多边形内外(C#)以及确定内外两点连线与边界的交点
  • SQL语句(DML)