結果

問題 No.756 チャンパーノウン定数 (1)
コンテスト
ユーザー ciel
提出日時 2018-12-06 10:27:07
言語 C90
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,057 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 101 ms
コンパイル使用メモリ 28,376 KB
最終ジャッジ日時 2026-02-24 00:59:44
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c:9:1: error: C++ style comments are not allowed in ISO C90
    9 | //isatty
      | ^
main.c:9:1: note: (this will be reported only once per input file)

ソースコード

diff #
raw source code

/*
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