結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2018-05-31 13:58:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 626 bytes |
コンパイル時間 | 1,531 ms |
コンパイル使用メモリ | 166,928 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-30 08:31:09 |
合計ジャッジ時間 | 4,206 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 11 RE * 17 |
コンパイルメッセージ
main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 11 | main(){ | ^~~~
ソースコード
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; int INF = (1LL << 30) - 1; int MOD = 1e9+7; ll gcd (ll a,ll b){ return b ? gcd(b,a%b) : a; } main(){ string S; cin >> S; int cnt[10] = {}; for(auto c:S)cnt[c - '0']++; int c = 0; for(auto i:cnt){ c += (bool)i; } if(c == 1){ cout << S << endl; return 0; } ll ans = stoi(S); rep(i,S.size()-1){ swap(S[i], S.back()); ans = gcd(ans, stoll(S)); swap(S[i], S.back()); } cout << ans << endl; }