結果
| 問題 |
No.1050 Zero (Maximum)
|
| コンテスト | |
| ユーザー |
hamray
|
| 提出日時 | 2021-05-26 14:13:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 5,447 bytes |
| コンパイル時間 | 1,948 ms |
| コンパイル使用メモリ | 178,840 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 10:03:04 |
| 合計ジャッジ時間 | 2,848 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define MOD 1000000007
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-12, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集
typedef string::const_iterator State;
ll GCD(ll a, ll b){
return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
return a/GCD(a, b) * b;
}
#include <vector>
#include <cassert>
#include <iostream>
template<int64_t mod>
struct Modint{
int x;
Modint(long y = 0) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
Modint& operator++() {
x++;
if(x == mod) x = 0;
return *this;
}
Modint& operator--() {
if(x == 0) x = mod;
x--;
return *this;
}
Modint& operator+=(const Modint& a) {
x += a.x;
if(x >= mod) x -= mod;
return *this;
}
Modint& operator-=(const Modint& a) {
x += mod - a.x;
if(x >= mod) x -= mod;
return *this;
}
Modint& operator*=(const Modint& a) {
x = (1LL) * x * a.x % mod;
return *this;
}
Modint& operator/=(const Modint& a) {
x *= a.inv();
return *this;
}
Modint operator+() const { return *this; }
Modint operator-() const { return Modint(-x); }
Modint operator+(const Modint& a) const { return Modint(*this) += a; }
Modint operator-(const Modint& a) const { return Modint(*this) -= a; }
Modint operator*(const Modint& a) const { return Modint(*this) *= a; }
Modint operator/(const Modint& a) const { return Modint(*this) /= a; }
Modint operator==(const Modint& a) const { return x == a.x; }
Modint operator!=(const Modint& a) const { return x != a.x; }
Modint pow(long long n) const {
Modint x = *this, r = 1;
while(n) {
if(n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
Modint inv() const {
int u = 1, v = 0, a = x, b = mod, t;
while(b) {
t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
return Modint(u);
}
friend std::ostream& operator<< (std::ostream& os, const Modint& a) {
return os << a.x;
}
};
template<typename T>
struct Matrix{
int row, col;
std::vector<std::vector<T>> A;
Matrix() { row = col = 1; }
Matrix(int h, int w, T val = 0) : row(h), col(w), A(row, std::vector<T>(col, val)){}
Matrix(const std::vector<std::vector<T>> &v) : row(v.size()), col(v[0].size()), A(v){}
int GetRow() const { return row; }
int GetCol() const { return col; }
const std::vector<T>& operator[](int i) const { return A[i]; }
std::vector<T>& operator[](int i) { return A[i]; }
Matrix E(int n) {
Matrix M(n, n);
for(int i=0; i<n; i++) M[i][i] = 1;
return M;
}
Matrix& operator+=(const Matrix& B) {
int n = GetRow(), m = GetCol();
assert(n == B.size()); assert(m == B[0].size());
Matrix C(n, m);
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
C[i][j] = A[i][j] + B[i][j];
}
}
return *this = C;
}
Matrix& operator-=(const Matrix& B) {
int n = GetRow(), m = GetCol();
assert(n == B.size()); assert(m == B[0].size());
Matrix C(n, m);
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
C[i][j] = A[i][j] - B[i][j];
}
}
return *this = C;
}
Matrix& operator*=(const Matrix& B) {
int k = GetRow(), l = GetCol(), n = B.GetRow(), m = GetCol();
assert(l == n);
Matrix C(k, m);
for(int i=0; i<k; i++) {
for(int j=0; j<m; j++) {
for(int k=0; k<n; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
return *this = C;
}
Matrix& operator^=(long long n) {
Matrix B = Matrix::E(GetRow());
while(n > 0) {
if(n&1) B = B * (*this);
*this = (*this) * (*this);
n >>= 1;
}
return *this = B;
}
Matrix operator+(const Matrix& B){ return Matrix(*this) += B; }
Matrix operator-(const Matrix& B){ return Matrix(*this) -= B; }
Matrix operator*(const Matrix& B){ return Matrix(*this) *= B; }
Matrix operator^(long long n){ return Matrix(*this) ^= n; }
friend std::ostream& operator<< (std::ostream& os, const Matrix& m) {
for(int i=0; i<m.GetRow(); i++) {
for(int j=0; j<m.GetCol(); j++) {
if(j != 0) os << ' ';
os << m.A[i][j];
}
os << '\n';
}
return os;
}
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int M, K; cin >> M >> K;
Matrix<Modint<1000000007>> m(M, M, 1);
for(int i=0; i<M; i++) {
for(int j=0; j<M; j++) {
m[(i*j)%M][j] = m[(i*j)%M][j] + 1;
}
}
auto m2 = m^K;
cout << m2[0][0] << endl;
return 0;
}
hamray