結果

問題 No.1842 Decimal Point
ユーザー publfl2publfl2
提出日時 2022-02-18 21:36:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 43,104 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 18:41:27
合計ジャッジ時間 1,416 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 45 ms
4,376 KB
testcase_02 AC 151 ms
4,376 KB
testcase_03 AC 112 ms
4,380 KB
testcase_04 AC 94 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>

std::pair<long long int, long long int> func(int k, long long int mod)
{
	if(k==0) return std::make_pair(0,1);
	else if(k%2==1)
	{
		std::pair<long long int, long long int> P = func(k-1,mod);
		P.first*=10, P.second*=10;
		P.first+=(P.second/mod), P.second%=mod;
		P.first%=10;
		return P;
	}
	else
	{
		std::pair<long long int, long long int> P = func(k/2,mod);
		std::pair<long long int, long long int> P2;
		long long int t = (2*P.first*P.second)%10;
		long long int t3 = (P.first*P.first)%10;
		t3 *= mod, t3 %= 10;
		t += t3, t %= 10;
		long long int t2 = (P.second*P.second);
		t += (t2/mod), t2%=mod;
		t%=10;
		return std::make_pair(t,t2);
	}
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		long long int a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		if(b==1) printf("0\n");
		else
		{
			std::pair<long long int, long long int> P = func(c,b);
			P.first*=a, P.second*=a;
			P.first+=(P.second/b), P.second%=b;
			P.first%=10;
			printf("%lld\n",P.first);
		}
	}
}
0