結果
| 問題 | No.443 GCD of Permutation | 
| コンテスト | |
| ユーザー |  Darsein | 
| 提出日時 | 2016-11-17 17:59:48 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 1,000 ms | 
| コード長 | 810 bytes | 
| コンパイル時間 | 2,242 ms | 
| コンパイル使用メモリ | 164,964 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-14 00:01:30 | 
| 合計ジャッジ時間 | 3,055 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 28 | 
ソースコード
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
bool isDiv(string s, int d){
  int cur = 0;
  rep(i,s.size()){
    cur = cur * 10 + (int)(s[i]-'0');
    while( cur >= d ) cur -= d;
  }
  return cur == 0;
}
int main(){
  string s;
  cin >> s;
  int l = s.size();
  vector<int> occ_d;
  rep(i,l) occ_d.emplace_back( s[i]-'0' );
  sort(occ_d.begin(), occ_d.end());
  occ_d.erase( unique(occ_d.begin(), occ_d.end()), occ_d.end() );
  if(occ_d.size() == 1){
    cout << s << endl;
    return 0;
  }
  int gcd = 0;
  for(int a : occ_d){
    for(int b : occ_d){
      int dif = abs(9*a - 9*b);
      gcd = __gcd(gcd, dif);
    }
  }
  int ans = 1;
  for(int i=gcd;i>=1;i--){
    if(gcd%i == 0 and isDiv(s, i)){
      ans = i; break;
    }
  }
  cout << ans << endl;
}
            
            
            
        