結果

問題 No.1312 Snake Eyes
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-12-09 15:17:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 3,248 bytes
コンパイル時間 2,905 ms
コンパイル使用メモリ 109,216 KB
実行使用メモリ 27,268 KB
最終ジャッジ日時 2023-08-20 11:19:28
合計ジャッジ時間 17,568 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,164 KB
testcase_01 AC 57 ms
21,040 KB
testcase_02 AC 58 ms
23,136 KB
testcase_03 AC 57 ms
20,976 KB
testcase_04 AC 57 ms
21,112 KB
testcase_05 AC 56 ms
21,164 KB
testcase_06 AC 58 ms
21,076 KB
testcase_07 AC 57 ms
22,976 KB
testcase_08 AC 59 ms
18,900 KB
testcase_09 AC 57 ms
21,068 KB
testcase_10 AC 57 ms
19,124 KB
testcase_11 AC 57 ms
23,100 KB
testcase_12 AC 57 ms
21,120 KB
testcase_13 AC 56 ms
21,188 KB
testcase_14 AC 58 ms
23,024 KB
testcase_15 AC 58 ms
19,064 KB
testcase_16 AC 57 ms
20,992 KB
testcase_17 AC 56 ms
21,072 KB
testcase_18 AC 57 ms
21,016 KB
testcase_19 AC 57 ms
20,976 KB
testcase_20 AC 57 ms
20,948 KB
testcase_21 AC 58 ms
23,136 KB
testcase_22 AC 57 ms
19,032 KB
testcase_23 AC 56 ms
19,040 KB
testcase_24 AC 59 ms
23,156 KB
testcase_25 AC 58 ms
21,060 KB
testcase_26 AC 57 ms
23,132 KB
testcase_27 AC 56 ms
21,044 KB
testcase_28 AC 58 ms
20,940 KB
testcase_29 AC 59 ms
20,940 KB
testcase_30 AC 60 ms
21,068 KB
testcase_31 AC 57 ms
20,932 KB
testcase_32 AC 57 ms
20,968 KB
testcase_33 AC 57 ms
21,124 KB
testcase_34 AC 58 ms
21,084 KB
testcase_35 AC 57 ms
20,968 KB
testcase_36 AC 57 ms
20,844 KB
testcase_37 AC 59 ms
21,176 KB
testcase_38 AC 62 ms
25,156 KB
testcase_39 AC 75 ms
25,308 KB
testcase_40 AC 66 ms
27,260 KB
testcase_41 AC 65 ms
27,100 KB
testcase_42 AC 59 ms
21,092 KB
testcase_43 AC 64 ms
25,184 KB
testcase_44 AC 60 ms
21,184 KB
testcase_45 AC 64 ms
27,132 KB
testcase_46 AC 65 ms
25,160 KB
testcase_47 AC 62 ms
23,124 KB
testcase_48 AC 315 ms
27,124 KB
testcase_49 AC 287 ms
24,976 KB
testcase_50 AC 241 ms
25,092 KB
testcase_51 AC 147 ms
25,060 KB
testcase_52 AC 337 ms
27,048 KB
testcase_53 AC 270 ms
25,104 KB
testcase_54 AC 312 ms
27,120 KB
testcase_55 AC 169 ms
25,104 KB
testcase_56 AC 215 ms
27,228 KB
testcase_57 AC 220 ms
23,104 KB
testcase_58 AC 272 ms
27,236 KB
testcase_59 AC 139 ms
27,080 KB
testcase_60 AC 210 ms
27,132 KB
testcase_61 AC 349 ms
27,188 KB
testcase_62 AC 161 ms
27,076 KB
testcase_63 AC 58 ms
23,100 KB
testcase_64 AC 68 ms
25,216 KB
testcase_65 AC 86 ms
25,084 KB
testcase_66 AC 57 ms
21,176 KB
testcase_67 AC 58 ms
22,976 KB
testcase_68 AC 70 ms
25,032 KB
testcase_69 AC 56 ms
20,900 KB
testcase_70 AC 297 ms
25,064 KB
testcase_71 AC 190 ms
27,116 KB
testcase_72 AC 68 ms
25,260 KB
testcase_73 AC 58 ms
21,088 KB
testcase_74 AC 59 ms
23,212 KB
testcase_75 AC 56 ms
21,064 KB
testcase_76 AC 342 ms
25,072 KB
testcase_77 AC 353 ms
27,240 KB
testcase_78 AC 349 ms
27,268 KB
testcase_79 AC 273 ms
27,216 KB
testcase_80 AC 348 ms
25,048 KB
testcase_81 AC 358 ms
27,156 KB
testcase_82 AC 348 ms
25,104 KB
testcase_83 AC 357 ms
27,124 KB
testcase_84 AC 350 ms
27,244 KB
testcase_85 AC 331 ms
25,108 KB
testcase_86 AC 307 ms
27,108 KB
testcase_87 AC 194 ms
25,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Diagnostics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.L;
		var q=Sqrt(n);
		int m=(int)Log(n,2)+1;
		long ans=n+1;
		if(n>2){ans=n-1;}
		for(int i = 2;i<q;i++) {
			if(n%i==0&&i*((long)i+1)!=n){ans=Min(n/i-1,ans);}
			Nsn nsn=new Nsn(n,i,m);
			var b=0L;
			for(int j = m-1;j>=0;j--) {
				if(b==0&&nsn[j]!=0){b=nsn[j];}
				if(b!=nsn[j]){b=-1;break;}
			}
			if(b!=-1){ans=Min(i,ans);}
		}
		Console.WriteLine("{0}",ans);
	}
}
public struct Nsn{
	public long[] h;
	public long p,q;
	public Nsn(long n,int p,int k){
		this.p=p;
		q=p-1;
		h=new long[k];
		for(int i = 0;n>0;i++) {
			h[i]=n%p;
			n/=p;
		}
	}
	public void Add(){
		for(int i = 0;i<h.Length;i++) {
			if(++h[i]==p){h[i]=0;}
			else{break;}
		}
	}
	public void Sub(){
		for(int i = 0;i<h.Length;i++) {
			if(--h[i]==255){h[i]=q;}
			else{break;}
		}
	}
	public override string ToString()=>string.Join(" ",h.Reverse());
	public long this[int i]{get{return h[i];}}
}
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(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).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