結果

問題 No.756 チャンパーノウン定数 (1)
ユーザー cielciel
提出日時 2018-12-06 10:26:53
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 29,360 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 02:03:00
合計ジャッジ時間 1,151 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 0 ms
4,352 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 0 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 0 ms
4,352 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 AC 0 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘main’ 内:
main.c:35:19: 警告: 関数 ‘fileno’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   35 |         if(isatty(fileno(stdin))){
      |                   ^~~~~~

ソースコード

diff #

/*
Code Teller [nthdigit]
input: standard input
output: standard output
*/

#include <stdio.h>
#include <stdlib.h>
//isatty
#if defined(WIN32) || (!defined(__GNUC__) && !defined(__clang__))
	#include <io.h>
#else
	#include <unistd.h>
#endif

int solve(long long n,long long starting,int base){
	n+=starting-2;
	long long digits=1;
	long long expbase=1;
	long long x;
	for(;(x=digits*expbase*(base-1))<=n;n-=x){
		digits++;
		expbase*=base;
	}
	//(digits)桁の数を並べた中のn桁目を求めれば良い
	long long num=expbase+n/digits;
	long long d=digits-1-n%digits;
	for(;d--;num/=base);
	return num%base;
}

int main(int argc,char **argv){
	long long starting=1;
	int base=10;
	if(isatty(fileno(stdin))){
		fprintf(stderr,"nthdigit [starting=%lld] [base=%d] [<nthdigit.txt]\n",starting,base);
	}

	if(argc>2)base=strtol(argv[2],NULL,10);
	if(argc>1)starting=strtoll(argv[1],NULL,base);

	long long n;
	for(;;){
		if(isatty(fileno(stdin)))printf("input> ");
		if(scanf("%lld",&n)<0)return 0;
		printf("%d\n",solve(n,starting,base));
	}
	return 0;
}
0