結果
| 問題 | 
                            No.2766 Delicious Multiply Spice
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2024-06-01 11:56:16 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 21 ms / 2,000 ms | 
| コード長 | 744 bytes | 
| コンパイル時間 | 560 ms | 
| コンパイル使用メモリ | 40,960 KB | 
| 最終ジャッジ日時 | 2025-02-21 19:00:51 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 8 | 
| other | AC * 31 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   49 |   scanf("%lld", &n);
      |   ~~~~~^~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 2766.cc:  No.2766 Delicious Multiply Spice - yukicoder
 */
#include<cstdio>
#include<algorithm>
 
using namespace std;
/* constant */
const int MAX_M = 60;
/* typedef */
typedef long long ll;
/* global variables */
char s[MAX_M + 4];
/* subroutines */
int rec(ll n, int k) {
  if (n <= 2) return (n == 1) ? k : 0;
  if ((n - 1) % 2 == 0) {
    s[k++] = 'A';
    int m = rec((n - 1) / 2, k);
    if (m > 0) return m;
    k--;
  }
  if ((n - 1) % 3 == 0) {
    s[k++] = 'B';
    int m = rec((n - 1) / 3, k);
    if (m > 0) return m;
    k--;
  }
  return 0;
}
/* main */
int main() {
  ll n;
  scanf("%lld", &n);
  int m = rec(n, 0);
  reverse(s, s + m);
  s[m] = '\0';
  puts(s);
  
  return 0;
}
            
            
            
        
            
tnakao0123