結果
問題 | No.1632 Sorting Integers (GCD of M) |
ユーザー |
![]() |
提出日時 | 2021-07-30 22:19:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,484 bytes |
コンパイル時間 | 3,250 ms |
コンパイル使用メモリ | 182,068 KB |
最終ジャッジ日時 | 2025-01-23 12:05:08 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 59 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #include <atcoder/all> #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair<int, int> P; using mint=modint1000000007; ll powmod(ll a, ll k, ll MOD){ ll ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=MOD; } ap=ap*ap; ap%=MOD; k>>=1; } return ans; } int main() { int n; cin>>n; ll c[10]; int k=0; for(int i=1; i<=9; i++){ cin>>c[i]; if(c[i]) k++; } if(k==1){ for(int i=1; i<=9; i++){ if(c[i]){ mint ans=(mint(10).pow(n)-1)/9*i; cout<<ans.val()<<endl; } } return 0; } int g=0, pr=-1; for(int i=1; i<=9; i++){ if(c[i] && pr==-1){ pr=i; }else if(c[i]){ g=gcd(g, i-pr); } } g*=9; int r=0, d=0; for(int i=1; i<=9; i++){ int r1=(powmod(10, c[i], 9*g)+9*g-1)*i%(9*g)/9; int q=powmod(10, d, g); r=(r+r1*q)%g; d+=c[i]; } g=gcd(r, g); cout<<g<<endl; return 0; }