zoukankan      html  css  js  c++  java
  • Parco_Love_gcd

    传送门

    出题人说正解为RMQ,鄙人实在太蒟蒻了,不会呀只能暴力……

    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define re register
    const int N=1e6+10;
    const int mod=1e9+7;
    void read(int &a)
    {
        a=0;
        int d=1;
        char ch;
        while(ch=getchar(),ch>'9'||ch<'0')
            if(ch=='-')
                d=-1;
        a=ch-'0';
        while(ch=getchar(),ch>='0'&&ch<='9')
            a=a*10+ch-'0';
        a*=d;
    }
    void write(int x)
    {
        if(x<0)
            putchar(45),x=-x;
        if(x>9)
            write(x/10);
        putchar(x%10+'0');
    }
    int a[N];
    int GCD(int a,int b)
    {
        return b==0?a:GCD(b,a%b);
    }
    int main()
    {
        int n;
        read(n);
        ll ans=0,gcd;
        read(a[0]);
        gcd=a[0];
        for(re int i=1;i<n;i++)
            read(a[i]),gcd=GCD(gcd,a[i]);
        for(re int i=0;i<n;i++)
        {
            int now=a[i];
            for(re int j=i;j<n;j++)
            {
                if(now==gcd)
                {
                    ans=(ans+(n-j)*gcd)%mod;
                    break;
                }
                now=GCD(now,a[j]);
                ans+=now;
                ans%=mod;
            }
        }
        write(ans);
        return 0;
    }
  • 相关阅读:
    媒体查询漫谈——@media Queries
    JavaScript工具函数集
    什么是BFC、IFC、GFC和FFC
    HTTP与HTTPS的区别
    reflow 和 repaint
    客户端检测
    ajax
    批量删除
    数据访问
    登录主页面代码
  • 原文地址:https://www.cnblogs.com/acm1ruoji/p/10706894.html
Copyright © 2011-2022 走看看