BZOJ 4488/4052 gcd

思路:

一开始 我是想 对于固定的左端点 从左到右 最多有 log种取值  且单调递减  那不妨倍增预处理+二分GCD在哪变了.. 复杂度O(nlog^2n)

gcd最多log种取值..

好了我们可以暴力了...

复杂度O(nlogn)

//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int cases,n,top,temp;
ll xx,ans;
struct Node{int id;ll gcd;}jy[33],al[33];
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
        scanf("%d",&n),ans=top=0;
        for(int i=1;i<=n;i++){
            scanf("%lld",&xx),temp=0;
            jy[++top].gcd=0,jy[top].id=i;
            for(int j=1;j<=top;j++)jy[j].gcd=gcd(jy[j].gcd,xx);
            for(int j=1;j<=top;j++)if(jy[j].gcd!=jy[j-1].gcd)
                ans=max(ans,jy[j].gcd*(i+1-jy[j].id)),jy[++temp]=jy[j];
            top=temp;
        }
        printf("%lld\n",ans);
}

 

转载于:https://www.cnblogs.com/SiriusRen/p/6637677.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值