AtCoder Beginner Contest 179 E - Sequence Sum (模拟)

题意:\(f(x,m)\)表示\(x\ mod\ m\),\(A_{1}=1\),而\(A_{n+1}=f(A^{2}_{n},M)\),求\(\sum^{n}_{i=1}A_{i}\).
题解:多算几个,会有一个循环节,直接模拟就好了.
代码:
ll n,x,m;
ll mp[N];
vector<ll> a; int main() {
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
scanf("%lld %lld %lld",&n,&x,&m);
ll pos=n;
ll tmp=0;
for(ll i=1;i<=n;++i){
if(i>1) x=x%m*x%m;
tmp+=x;
if(!mp[x]){
mp[x]=i;
a.pb(x);
}
else{
pos=i;
break;
}
}
if(mp[x]==n){
printf("%lld\n",tmp);
return 0;
}
ll res=0; for(ll i=0;i<mp[x]-1;++i){
res+=a[i];
}
ll cnt=0;
for(ll i=mp[x]-1;i<pos-1;++i){
cnt+=a[i];
}
ll len=pos-mp[x];
ll times=(n-mp[x]+1)/len;
ll rest=(n-mp[x]+1)%len;
res+=cnt*times; for(ll i=mp[x]-1;i<mp[x]-1+rest;++i){
res+=a[i];
} printf("%lld\n",res); return 0;
}
AtCoder Beginner Contest 179 E - Sequence Sum (模拟)的更多相关文章
- AtCoder Beginner Contest 179
比赛链接:https://atcoder.jp/contests/abc179/tasks A - Plural Form 题意 给出一个由小写字母组成的单词,如果单词以 $s$ 结尾,在单词的末尾加 ...
- AtCoder Beginner Contest 098 D - Xor Sum 2
D - Xor Sum 2 Time limit : 2sec / Memory limit : 1024MB Score : 500 points Problem Statement There i ...
- AtCoder Beginner Contest 188 C - ABC Tournament (模拟)
题意:有\(2^n\)个人站成一排比赛,刚开始每个人都和自己右边的人进行比赛,赢得人晋级下一轮(下标的小的在前面),不断重复这个过程,问最后拿到第二名的人的编号. 题解:根据题意,可以用vector直 ...
- AtCoder Beginner Contest 179 D - Leaping Tak (DP)
题意:给你一个数字\(n\)和\(k\)个区间,\(S\)表示所有区间的并的集合,你目前在\(1\),每次可以从集合中选择一个数字向右移动,问有多少种方法从\(1\)走到\(n\). 题解:我们从1开 ...
- AtCoder Beginner Contest 146_E - Rem of Sum is Num
预处理即可 我们要找的是 (f[i] - f[j]) % k == i - j 移项可得 f[i] - i = f[j] - j 在 i - j <= k 的条件下 因此题目变成了,对于每个右端 ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
随机推荐
- 【葵花宝典】kolla部署OpenStack-AllinOne
1.关闭防火墙以及内核安全机制 systemctl stop firewalld systemctl disable firewalld ##永久性关闭 setenforce 0 sed -i 's/ ...
- IP2188中文资料书
IP2188 是一款集成 12 种.用于 USB 输出端口的快充协议 IC,支持 USB 端口充电协议.支持 11种快充协议,包括 USB TypeC PD2.0/PD3.0/PPS DFP,HVDC ...
- 第一个 Maven 应用程序
概述 使用 Maven 创建一个 Java Web 应用程序 创建 Maven 项目 选择 File -> New -> Project... 选择 Maven 项目 填写项目信息 选择工 ...
- Supporting Multiple Versions of WebSocket Protocol 支持多版本WebSocket协议
https://tools.ietf.org/html/rfc6455#section-4.4 4.4. Supporting Multiple Versions of WebSocket Proto ...
- celery 动态配置定时任务
How to dynamically add or remove tasks to celerybeat? · Issue #3493 · celery/celery https://github.c ...
- __del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数
小结 1.cpy的垃圾回收会对调用__del__多次:pypy仅仅一次: https://www.liaoxuefeng.com/wiki/1016959663602400/1016966024263 ...
- Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe.
Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe. htt ...
- 选出ip记录表最近的10行数据
w select * from wip where id>(select (select max(id)from wip)-10) ;
- 【笔记】学习markdown
经过来自学长(姐?)的 嘲讽 善意提醒后,我才知道这个博客园好像 资瓷 markdown 于是我决定要认真学习markdown(绝不是因为洛谷题解又过不去了) 正常点: 由于没人教,我上网查了一下 一 ...
- (五)整合 Swagger2 ,构建接口管理界面
整合 Swagger2 ,构建接口管理界面 1.Swagger2简介 1.1 Swagger2优点 1.2 Swagger2常用注解 2.SpringBoot整合Swagger2 2.1 Swagee ...