結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2025-01-29 12:23:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 790 bytes |
コンパイル時間 | 2,111 ms |
コンパイル使用メモリ | 192,740 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-29 12:23:59 |
合計ジャッジ時間 | 3,548 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 5 | scanf("%s",s+1); | ~~~~~^~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; char s[10005]; int main(){ scanf("%s",s+1); int n=strlen(s+1),fl=1; for(int i=2;i<=n;++i)fl&=(s[i]==s[1]); if(fl){ printf("%s\n",s+1); return 0; } int p=8*81*5*7,h=0; for(int i=1;i<=n;++i)h=(10*h+(s[i]-'0'))%p; int d=__gcd(h,p),c=1; int f7=1; for(int i=2;i<=n;++i)f7&=((s[i]-s[1])%7==0); if(d%7==0&&f7)c*=7; int f5=1; for(int i=2;i<=n;++i)f5&=((s[i]-s[1])%5==0); if(d%5==0&&f5)c*=5; int g=8; for(int i=1;i<=n;++i)g=__gcd(g,s[i]-'0'); c*=g; int hh=0; for(int i=1;i<=n;++i)hh+=(s[i]-'0'); if(hh%3)c*=1; else if(hh%9)c*=3; else{ c*=9; int f3=1,f9=1; for(int i=2;i<=n;++i){ f3&=((s[i]-s[1])%3==0); f9&=((s[i]-s[1])%9==0); } if(d%81==0&&f9)c*=9; else if(d%27==0&&f3)c*=3; } printf("%d\n",c); return 0; }