結果

問題 No.443 GCD of Permutation
ユーザー ytqm3ytqm3
提出日時 2022-04-08 18:45:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 724 bytes
コンパイル時間 3,760 ms
コンパイル使用メモリ 387,028 KB
最終ジャッジ日時 2025-01-28 15:44:44
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;

int main(){
  string S;
  cin>>S;
  int N=S.size();
  vector<int> cnt(10);
  for(int i=0;i<N;++i){
    cnt[S[i]-'0']++;
  }
  for(int i=0;i<10;++i){
    if(cnt[i]==N){
      cout<<S<<endl;
      return 0;
    }
  }
  int ans=1,dsm=0;
  for(int i=0;i<10;++i){
    dsm+=i*cnt[i];
  }
  mp::cpp_int T(S);
  for(int u=2;u<=9;++u){
  	for(int i=0;i<u;++i){
  		int t=0;
  		for(int j=i;j<=9;j+=u){
  			t+=cnt[j];
  		}
  		if(t==N && T%u==0){
  			ans=lcm(ans,u);
  		}
  	}
  }
  ans*=9;
  for(int i=ans;i>=1;--i){
  	if(ans%i==0){
  		if(T%i==0){
  			cout<<i<<endl;
  			return 0;
  		}
  	}
  }
}
0