結果
| 問題 |
No.1842 Decimal Point
|
| コンテスト | |
| ユーザー |
publfl2
|
| 提出日時 | 2022-02-18 21:36:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 2,000 ms |
| コード長 | 1,020 bytes |
| コンパイル時間 | 302 ms |
| コンパイル使用メモリ | 43,264 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-29 08:27:35 |
| 合計ジャッジ時間 | 1,337 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 |
ソースコード
#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);
}
}
}
publfl2