結果

問題 No.1036 Make One With GCD 2
ユーザー xllend3xllend3
提出日時 2020-04-24 22:17:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,135 ms / 2,000 ms
コード長 3,182 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 166,368 KB
実行使用メモリ 95,568 KB
最終ジャッジ日時 2023-10-14 19:24:11
合計ジャッジ時間 24,531 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 512 ms
95,320 KB
testcase_01 AC 474 ms
95,452 KB
testcase_02 AC 487 ms
95,416 KB
testcase_03 AC 121 ms
39,148 KB
testcase_04 AC 259 ms
64,704 KB
testcase_05 AC 2 ms
5,484 KB
testcase_06 AC 2 ms
5,476 KB
testcase_07 AC 165 ms
43,212 KB
testcase_08 AC 126 ms
37,000 KB
testcase_09 AC 671 ms
93,244 KB
testcase_10 AC 617 ms
86,864 KB
testcase_11 AC 682 ms
94,992 KB
testcase_12 AC 636 ms
87,972 KB
testcase_13 AC 883 ms
91,252 KB
testcase_14 AC 886 ms
92,088 KB
testcase_15 AC 822 ms
86,368 KB
testcase_16 AC 835 ms
87,312 KB
testcase_17 AC 864 ms
89,656 KB
testcase_18 AC 3 ms
7,672 KB
testcase_19 AC 3 ms
7,672 KB
testcase_20 AC 4 ms
7,756 KB
testcase_21 AC 3 ms
7,592 KB
testcase_22 AC 820 ms
85,432 KB
testcase_23 AC 592 ms
64,888 KB
testcase_24 AC 849 ms
88,632 KB
testcase_25 AC 775 ms
81,044 KB
testcase_26 AC 811 ms
83,964 KB
testcase_27 AC 2 ms
5,744 KB
testcase_28 AC 2 ms
5,436 KB
testcase_29 AC 2 ms
5,484 KB
testcase_30 AC 2 ms
5,476 KB
testcase_31 AC 2 ms
5,484 KB
testcase_32 AC 2 ms
5,548 KB
testcase_33 AC 2 ms
5,532 KB
testcase_34 AC 2 ms
5,640 KB
testcase_35 AC 2 ms
5,452 KB
testcase_36 AC 2 ms
5,456 KB
testcase_37 AC 2 ms
5,612 KB
testcase_38 AC 486 ms
95,420 KB
testcase_39 AC 528 ms
95,540 KB
testcase_40 AC 586 ms
64,728 KB
testcase_41 AC 1,122 ms
95,380 KB
testcase_42 AC 1,135 ms
95,544 KB
testcase_43 AC 1,008 ms
95,256 KB
testcase_44 AC 1,080 ms
95,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=501111,M=111111;
int l,m,n,t,C;
ll a[N];
ll g[N][22];
int lg[N];
ll calc(int x,int y){
	int p=lg[y-x+1]-1;
	if(x==y)return a[x];
	// printf(" %d %lld %lld\n",p,g[x][p],g[y-(1<<p)+1][p]);
	return gcd(g[x][p],g[y-(1<<p)+1][p]);
}
int main(){
#ifdef LOCAL
	freopen("D.in","r",stdin);freopen("D.out","w",stdout);
#endif
	scanf("%d",&n);
	rep(i,1,n)scanf("%lld",&a[i]),g[i][0]=a[i];
	rep(i,1,20)rep(j,1,n-(1<<i-1))g[j][i]=gcd(g[j][i-1],g[j+(1<<i-1)][i-1]);
	rep(i,1,n+10)lg[i]=lg[i/2]+1;
	// rep(i,1,n)rep(j,i,n)printf("%d %d %lld\n",i,j,calc(i,j));
	// rep(i,0,2)rep(j,1,n)printf("%d %d %lld\n",i,j,g[j][i]);
	int pt=1;ll v=a[1];
	ll ans=0;
	rep(i,1,n){
		v=gcd(v,a[i]);
		while(v==1&&pt<=i){
			++pt;if(pt<=i)v=calc(pt,i);else v=a[i+1];
		}
		ans+=pt-1;
		// printf("%d\n",pt);
	}
	cout<<ans<<endl;
	return 0;
}
0