結果

問題 No.747 循環小数N桁目 Hard
ユーザー karinohito
提出日時 2021-08-04 16:30:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 168,432 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 15:09:14
合計ジャッジ時間 4,511 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 120
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;

int main() {
	string S="285714";
	


	string N;
	cin>>N;
	bool T=((N[N.size()-1]-'0')%2==0);
	ll Th=0;
	rep(i,N.size()){
		Th+=N[i]-'0';
		Th%=3;
	}
	string K;
	cin>>K;
	K="0"+K;
	ll f=(K[K.size()-2]-'0')*10+K[K.size()-1]-'0';

	f%=4;
	if(f==0)f+=4;
	ll s=0;
	if(T){
		if(Th==0){
			s=0;
		}
		else if(Th==1){
			s=4;
		}
		else{
			s=2;
		}
	}
	else{
		if(Th==0){
			s=3;
		}
		else if(Th==1){
			s=1;
		}
		else{
			s=5;
		}
	}
	//cout<<s<<endl;
	ll num=pow(s,f);
	num+=5;
	num%=6;
	cout<<S[num]<<endl;
}
0