出题人说正解为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; }