結果

問題 No.1842 Decimal Point
ユーザー publfl2publfl2
提出日時 2022-02-18 21:31:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 934 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 43,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 18:35:43
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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