結果

問題 No.593 4進FizzBuzz
ユーザー どららどらら
提出日時 2017-11-10 22:57:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,861 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 184,212 KB
実行使用メモリ 12,436 KB
最終ジャッジ日時 2024-05-03 13:07:40
合計ジャッジ時間 5,994 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
12,436 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class Bignum{
public:
  Bignum(){}
  Bignum(string s){
    for(int i=0;i<s.length();i++) d.push_front(s[i]-'0');
    normalize();
  }
  Bignum &normalize(){
    for(int i=d.size()-1;i>=0;i--){ if(d[i]!=0) break; d.pop_back(); }
    return *this;
  }
  int operator[](int i){ return i>=d.size()?0:d[i]; }
  int size(){ return normalize(),d.size(); }
  void toZero(){ d.clear(); d.push_front(0); }
  void toOne(){ d.clear(); d.push_front(1); }
  Bignum &inc(){ Bignum one("1"); return operator+=(one); }
  Bignum &operator+=(Bignum n){
    int l=max(size(),n.size());
    d.resize(l+1,0);
    for(int c=0,i=0;i<=l;i++) d[i]=(c=d[i]+n[i]+c/10)%10;
    return normalize();
  }
  Bignum &operator-=(Bignum n){
    //assert(size()>=n.size());
    for(int c=0,i=0;i<d.size();i++) d[i]=((c=d[i]-n[i]+(c-9)/10)+10)%10;
    return normalize();
  }
  Bignum &operator*=(int n){
    for(int i=0;i<15;i++) d.push_back(0);
    for(int c=0,i=0;i<d.size();i++) d[i]=(c=d[i]*n+c/10)%10;
    return normalize();
  }
  Bignum &operator*=(ull n){
    for(int i=0;i<25;i++) d.push_back(0);
    for(ull c=0,i=0;i<d.size();i++) d[i]=(c=d[i]*n+c/10ULL)%10ULL;
    return normalize();
  }
  Bignum operator+(Bignum n){ return Bignum(*this)+=n; }
  Bignum operator-(Bignum n){ return Bignum(*this)-=n; }
  Bignum operator*(int n){ return Bignum(*this)*=n; }
  Bignum operator*(ull n){ return Bignum(*this)*=n; }
  Bignum operator*(Bignum n){
    Bignum ret;
    int ka=size(),kb=n.size();
    ret.d.resize(ka+kb,0);
    for(int i=0;i<ka;i++) for(int c=0,j=0;j<=kb;j++) ret.d[i+j]=(c=ret.d[i+j]+d[i]*n[j]+c/10)%10;
    return ret.normalize();
  }
  Bignum &operator*=(Bignum n){ return (*this)=(*this)*n; }

  int div(int n){
    int c=0;
    for(int i=size()-1;i>=0;i--) d[i]=(c=c%n*10+d[i])/n;
    return c%n;
  }
  Bignum &operator<<=(int n){
    for(int i=0;i<n;i++) d.push_front(0);
    return normalize();
  }
  Bignum operator<<(int n){ return Bignum(*this)<<=n; }
  bool operator>(Bignum n){
    if(size()!=n.size()) return size()>n.size();
    for(int i=size()-1;i>=0;i--) if(d[i]!=n[i]) return d[i]>n[i];
    return false;
  }
  deque<int> d;
};

int main(){
  string N;
  cin >> N;

  Bignum m("0");
  Bignum p("1");
  for(int i=N.size()-1; i>=0; i--){
    int a = N[i]-'0';
    m += p * a;
    p *= 4;
  }

  string ret = "";

  int cnt = 0;
  for (int i=m.d.size()-1;i>=0;i--) cnt += m.d[i];

  if(cnt%3 == 0){
    ret += "Fizz";
  }
  if(m.d[0]%5 == 0){
    ret += "Buzz";
  }

  if(ret != ""){
    cout << ret << endl;
  }else{
    cout << N << endl;
  }
  
  return 0;
}
0