結果

問題 No.1036 Make One With GCD 2
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-04-24 22:46:57
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,509 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 106,752 KB
実行使用メモリ 103,816 KB
最終ジャッジ日時 2024-04-25 10:18:01
合計ジャッジ時間 31,027 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 723 ms
103,632 KB
testcase_01 AC 658 ms
98,456 KB
testcase_02 AC 744 ms
98,464 KB
testcase_03 AC 201 ms
48,772 KB
testcase_04 AC 425 ms
70,052 KB
testcase_05 AC 27 ms
18,176 KB
testcase_06 AC 27 ms
18,176 KB
testcase_07 AC 332 ms
55,940 KB
testcase_08 AC 272 ms
46,856 KB
testcase_09 AC 896 ms
96,536 KB
testcase_10 AC 737 ms
91,072 KB
testcase_11 AC 790 ms
98,104 KB
testcase_12 AC 728 ms
91,544 KB
testcase_13 AC 957 ms
94,376 KB
testcase_14 AC 958 ms
95,460 KB
testcase_15 AC 901 ms
90,408 KB
testcase_16 AC 926 ms
91,168 KB
testcase_17 AC 957 ms
93,308 KB
testcase_18 AC 26 ms
18,944 KB
testcase_19 AC 27 ms
19,072 KB
testcase_20 AC 27 ms
19,328 KB
testcase_21 AC 29 ms
19,072 KB
testcase_22 AC 869 ms
89,696 KB
testcase_23 AC 650 ms
72,892 KB
testcase_24 AC 942 ms
92,368 KB
testcase_25 AC 866 ms
86,048 KB
testcase_26 AC 895 ms
88,476 KB
testcase_27 AC 21 ms
18,304 KB
testcase_28 AC 21 ms
18,176 KB
testcase_29 AC 20 ms
18,048 KB
testcase_30 AC 20 ms
18,304 KB
testcase_31 AC 24 ms
18,560 KB
testcase_32 AC 25 ms
18,688 KB
testcase_33 AC 22 ms
18,048 KB
testcase_34 AC 28 ms
18,816 KB
testcase_35 AC 29 ms
18,432 KB
testcase_36 AC 21 ms
18,048 KB
testcase_37 AC 21 ms
18,176 KB
testcase_38 AC 745 ms
98,308 KB
testcase_39 AC 779 ms
98,444 KB
testcase_40 AC 655 ms
73,028 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.La;
		Spt spt=new Spt(a);
		long ans=0;
		for(int i = 0;i<n;i++) {
			int lb=i-1,ub=n,mid=0;
			while(lb+1!=ub){
				mid=(ub+lb)/2;
				if(spt.Get(i,mid)==1){ub=mid;}
				else{lb=mid;}
			}
			ans+=n-ub;
		}
		Console.WriteLine(ans);
	}
}
public class Spt{
	private readonly long[][] d;
	private readonly int[] l;
	//private Func<int,int,int> Fu;
	public Spt(long[] a){
		int n=a.Length,m=(int)Log(n,2)+1;
		d=new long[m][];
		d[0]=new long[n];
		l=new int[n+1];
		for(int i=0;i<n;i++){
			d[0][i]=a[i];
			l[i+1]=l[i>>1]+1;
		}
		for(int i=1,k=1;i<m;i++,k<<=1){
			int p=n+1-(k<<1);
			d[i]=new long[p];
			for(int j=0;j<p;j++){d[i][j]=Gcd(d[i-1][j],d[i-1][j+k]);}
		}
	}
	public long Get(int a,int b){
		if(a>b){a^=b;b^=a;a^=b;}
		int p=l[b-a];
		return Gcd(d[p][a],d[p][b+1-(1<<p)]);
	}
	public long Gcd(long a,long b){
		long c=Max(a,b)%(b=Min(a,b));
		while(c!=0){
			a=b%c;
			b=c;
			c=a;
		}
		return b;
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0