标签:2015多校联赛#1
5 1 2 3 4 5
23
#include<stdio.h> int main() { int n,i,j,k,kk,a[100050]; while(scanf("%d",&n)!=EOF) { for(i=1; i<=n; i++) scanf("%d",&a[i]); long long suma=0; for(i=1; i<=n; i++) { for(j=i; j<=n; j++) { for(k=i; k<=j; k++)//相当于i { int flag=0; for(kk=i; kk <= j ; kk++)//相当于j { if(a[k]%a[kk] == 0 && k!=kk) { flag=1; break; } } if(flag!=1) { suma++; suma%=100000007; } } printf("%d %d=%d %d=%d\n",i,j,a[i],a[j],suma); } } printf("%I64d\n",suma); } }脑洞大开:换个思路是不是题意求的是找那些区间能满足第ai个值存在呢?
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; const int M = 10e5 + 5; const long mod = 1e9+7; int vis[M],a[M],l[M],r[M]; int main() { int n; while(~scanf("%d",&n)) { memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); memset(vis,0,sizeof(vis)); for(int i = 1;i <= n; ++i) { scanf("%d",&a[i]); r[i] = n+1; for(int j = a[i];j <= 10000; j+=a[i]) //找到离他最近的因子 { if(vis[j]) { r[vis[j]] = i; vis[j] = 0; } } vis[a[i]] = i; } memset(vis,0,sizeof(vis)); for(int i = n;i >= 1; --i) { for(int j = a[i];j <= 10000; j+=a[i]) { if(vis[j]) { l[vis[j]] = i; vis[j] = 0; } } vis[a[i]] = i; } long long ans = 0; for(int i = 1;i <= n; ++i) { ans = ((ans + (long long)(r[i]-i)*(long long)(i-l[i])%mod)%mod); } printf("%I64d\n",ans); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
Hdu 5288 OO’s Sequence 2015多小联赛A题
标签:2015多校联赛#1
原文地址:http://blog.csdn.net/u012349696/article/details/47018415