結果

問題 No.747 循環小数N桁目 Hard
ユーザー hanbei_dayo
提出日時 2020-08-22 18:57:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 101,860 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 12:10:12
合計ジャッジ時間 4,823 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 120
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <cassert>
#include <complex>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1e8;


int main() {
    string n,k;
    cin>>n>>k;
    reverse(n.begin(),n.end());
    reverse(k.begin(),k.end());
    int r = 0;
    int ten = 1;
    for(int i=0;i<n.length();i++){
        int x = n[i]-'0';
        if(i==0)r = (r+x)%6;
        else{
            ten = (ten*10)%6;
            r = (r + ten*x)%6;
        }
    }
    if(r==0)cout<<4<<endl;
    else{
        if(r==1)cout<<2<<endl;
        else{
            if(r==3)cout<<5<<endl;
            else{
                if(r==4)cout<<7<<endl;
                else{
                    int x = k[0]-'0';
                    if(x%2==0){
                        if(r==2)cout<<7<<endl;
                        else cout<<2<<endl;
                    }
                    else{
                        if(r==2)cout<<8<<endl;
                        else cout<<1<<endl;
                    }
                }
            }
        }
    }
}

0