結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-13 20:04:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,208 bytes |
| コンパイル時間 | 1,136 ms |
| コンパイル使用メモリ | 113,292 KB |
| 最終ジャッジ日時 | 2025-01-11 20:18:50 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 WA * 10 TLE * 1 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
string s,t; cin >> s;
t=s;
sort(t.begin(), t.end());
if(t[0]==t.back()){
cout << t << endl;
}
else{
ll n=s.size();
vector<int> v;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
v.push_back(9*((s[i]-'0')-(s[j]-'0')));
}
}
ll g=abs(v[0]);
for(ll y:v){
g=__gcd(g,abs(y));
}
if(n>18)cout << g << endl;
else{
n=stoll(s);
ll res=0;
for(ll i=1;i*i<=g;i++){
if(g%i==0){
if(n%i==0){
res=max(res,i);
}
if(n%(g/i)==0){
res=max(res,g/i);
}
}
}
cout << res << endl;
}
}
}