【gcd分块】BZOJ4921[互质序列]题解
来源:互联网 发布:网络运营托管 编辑:程序博客网 时间:2024/05/29 14:36
题目概述
给出一个序列
解题报告
预处理前缀
示例程序
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;const int maxn=100000,MOD=998244353;int n,blk,a[maxn+5],pre[maxn+5],suf[maxn+5],R[maxn+5],ans;int gcd(int a,int b) {if (!b) return a;return gcd(b,a%b);}inline void AMOD(int &x,int tem) {if ((x+=tem)>=MOD) x-=MOD;}int main(){ freopen("program.in","r",stdin); freopen("program.out","w",stdout); scanf("%d",&n);for (int i=1;i<=n;i++) scanf("%d",&a[i]); pre[1]=a[1];for (int i=2;i<=n;i++) pre[i]=gcd(pre[i-1],a[i]); suf[n]=a[n];R[++blk]=n; for (int i=n-1;i>=1;i--) {suf[i]=gcd(suf[i+1],a[i]);if (suf[i]!=suf[i+1]) R[++blk]=i;} R[++blk]=0;for (int i=2;i<=n-1;i++) AMOD(ans,pre[i]),AMOD(ans,suf[i]); for (int i=2;i<n;i++) for (int j=2;j<=blk;j++) if (i<=R[j-1]-1) AMOD(ans,(LL)gcd(pre[i-1],suf[R[j-1]])*(R[j-1]-max(i,R[j]))%MOD); return printf("%d\n",ans),0;}
阅读全文
0 0
- 【gcd分块】BZOJ4921[互质序列]题解
- bzoj4921: 互质序列
- [BZOJ4921][Lydsy六月份月赛 .E][二分][瞎搞]互质序列
- 【gcd分块+离线+树状数组】HDU5869[Different GCD Subarray Query]题解
- 【莫比乌斯函数+除法分块】BZOJ2820[YY的GCD]题解
- 【NOIP模拟题】【数学归纳法】【GCD】2016.11.16 第一题 LGTB 与序列 题解
- 【hdu5382】GCD?LCM! 题解
- Hdu5726:GCD—题解
- UVa 11426题解 GCD
- HDU4676 Sum Of Gcd (数论 + 分块)
- 【BZOJ】【P2821】【作诗(Poetize)】【题解】【分块】
- 【BZOJ】【P3343】【教主的魔法】【题解】【分块】
- 【BZOJ】【P2724】【Violet 6】【蒲公英】【题解】【分块】
- 【数学分析+除法分块】Codeforces830C[Bamboo Partition]题解
- 【BZOJ】【P2818】【Gcd】【数论】【题解】
- 【BZOJ】【P1441】【Min】【题解】【gcd】
- Codevs3657括号序列题解
- 【题解】dutoj1081 Prufer 序列
- 青鸟微信群邀请统计
- css top与bottom属性
- bzoj 1933: [Shoi2007]Bookcase 书柜的尺寸
- Linux源码包安装卸载教程 以apache httpd源码包安装为教程(APR not found)
- Codeforces Round439 C.The Intriguing Obsession
- 【gcd分块】BZOJ4921[互质序列]题解
- 使用ZooKeeper实现Java跨JVM的分布式锁
- JAVA的Md5工具类
- 剑指offer-打印出字符串的所有排列
- java中成员变量与局部变量的区别
- 一点 · 栈
- JAVA提高篇(12)--回退流PushbackInputStream
- 深入Bootstrap中data属性
- ASSERT()