結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | fgwiebfaoish |
提出日時 | 2020-04-26 02:56:34 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,263 ms / 2,000 ms |
コード長 | 5,250 bytes |
コンパイル時間 | 6,039 ms |
コンパイル使用メモリ | 108,032 KB |
実行使用メモリ | 98,452 KB |
最終ジャッジ日時 | 2024-09-16 14:09:09 |
合計ジャッジ時間 | 26,510 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 586 ms
98,264 KB |
testcase_01 | AC | 512 ms
98,440 KB |
testcase_02 | AC | 600 ms
98,440 KB |
testcase_03 | AC | 164 ms
48,636 KB |
testcase_04 | AC | 264 ms
70,184 KB |
testcase_05 | AC | 26 ms
18,176 KB |
testcase_06 | AC | 25 ms
18,176 KB |
testcase_07 | AC | 233 ms
55,692 KB |
testcase_08 | AC | 194 ms
46,844 KB |
testcase_09 | AC | 629 ms
96,412 KB |
testcase_10 | AC | 590 ms
90,932 KB |
testcase_11 | AC | 643 ms
97,972 KB |
testcase_12 | AC | 597 ms
91,672 KB |
testcase_13 | AC | 848 ms
94,620 KB |
testcase_14 | AC | 851 ms
95,328 KB |
testcase_15 | AC | 805 ms
90,664 KB |
testcase_16 | AC | 817 ms
91,040 KB |
testcase_17 | AC | 842 ms
93,188 KB |
testcase_18 | AC | 30 ms
18,816 KB |
testcase_19 | AC | 31 ms
19,200 KB |
testcase_20 | AC | 33 ms
19,584 KB |
testcase_21 | AC | 32 ms
19,456 KB |
testcase_22 | AC | 810 ms
89,680 KB |
testcase_23 | AC | 600 ms
73,028 KB |
testcase_24 | AC | 828 ms
92,624 KB |
testcase_25 | AC | 753 ms
86,188 KB |
testcase_26 | AC | 785 ms
88,476 KB |
testcase_27 | AC | 25 ms
18,176 KB |
testcase_28 | AC | 24 ms
18,304 KB |
testcase_29 | AC | 24 ms
18,176 KB |
testcase_30 | AC | 24 ms
18,176 KB |
testcase_31 | AC | 29 ms
18,816 KB |
testcase_32 | AC | 28 ms
18,560 KB |
testcase_33 | AC | 25 ms
18,176 KB |
testcase_34 | AC | 29 ms
18,560 KB |
testcase_35 | AC | 25 ms
18,048 KB |
testcase_36 | AC | 25 ms
18,176 KB |
testcase_37 | AC | 24 ms
18,304 KB |
testcase_38 | AC | 591 ms
98,304 KB |
testcase_39 | AC | 620 ms
98,320 KB |
testcase_40 | AC | 598 ms
72,904 KB |
testcase_41 | AC | 1,261 ms
98,312 KB |
testcase_42 | AC | 1,263 ms
98,444 KB |
testcase_43 | AC | 1,113 ms
98,188 KB |
testcase_44 | AC | 1,199 ms
98,452 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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,j=0;i<n;i++) { while(j<n&&spt.Get(i,j)!=1){j++;} if(j==n){break;} ans+=n-j; if(i==j){j++;} } Console.WriteLine(ans); } } public class Spt{ private readonly long[][] d; private readonly int[] l; 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;} } public class Sct{ private StreamReader sr; public Sct(string t){sr=new StreamReader(t);} public int I{get{return int.Parse(sr.ReadLine());}} public long L{get{return long.Parse(sr.ReadLine());}} public double D{get{return double.Parse(sr.ReadLine());}} public string S{get{return sr.ReadLine();}} public int[] Ia{get{return Array.ConvertAll(sr.ReadLine().Split(),int.Parse);}} public long[] La{get{return Array.ConvertAll(sr.ReadLine().Split(),long.Parse);}} public double[] Da{get{return Array.ConvertAll(sr.ReadLine().Split(),double.Parse);}} public string[] Sa{get{return sr.ReadLine().Split();}} public object[] Oa{get{return sr.ReadLine().Split();}} public int[] Ia2{get{return Array.ConvertAll(("0 "+sr.ReadLine()+" 0").Split(),int.Parse);}} public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+sr.ReadLine()).Split(),int.Parse);} public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+sr.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);} public long[] La2{get{return Array.ConvertAll(("0 "+sr.ReadLine()+" 0").Split(),long.Parse);}} public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+sr.ReadLine()).Split(),long.Parse);} public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+sr.ReadLine()+(c?" "+d.ToString():"")).Split(),long.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(sr.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,sr.ReadLine().Split());}return a;} }