結果
| 問題 |
No.681 Fractal Gravity Glue
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-28 23:18:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,073 bytes |
| コンパイル時間 | 1,278 ms |
| コンパイル使用メモリ | 108,756 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 23:28:04 |
| 合計ジャッジ時間 | 1,802 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
const int MOD = 1000000007;
// 行列の積
template <class T>
vector<vector<T> > matrixProduct(const vector<vector<T> >& x, const vector<vector<T> >& y)
{
int a = x.size();
int b = x[0].size();
int c = y[0].size();
vector<vector<T> > z(a, vector<T>(c, 0));
for(int i=0; i<a; ++i){
for(int j=0; j<c; ++j){
for(int k=0; k<b; ++k){
z[i][j] += x[i][k] * y[k][j];
z[i][j] %= MOD;
}
}
}
return z;
}
// 行列の累乗
template <class T>
vector<vector<T> > matrixPower(const vector<vector<T> >& x, int k)
{
int n = x.size();
vector<vector<T> > y(n, vector<T>(n, 0));
for(int i=0; i<n; ++i)
y[i][i] = 1; // 積の単位元
vector<vector<T> > z = x;
while(k > 0){
if(k & 1)
y = matrixProduct(y, z);
z = matrixProduct(z, z);
k >>= 1;
}
return y;
}
long long solve(long long b, long long d, long long cnt, long long weight, long long& n)
{
if(cnt > n)
return 0;
long long ans = solve(b + 1, d, cnt * (d + 1) + d, weight * (d + 1) + b * d, n);
long long x = n / (cnt + 1);
n -= (cnt + 1) * x;
ans += (weight + b) * x;
ans %= MOD;
return ans;
}
int main()
{
int n, b, d;
cin >> n >> b >> d;
vector<vector<long long> > mat =
{
{d+1, d, 0},
{0, 1, 1},
{0, 0, 1}
};
mat = matrixPower(mat, b);
long long ans = mat[0][1] + mat[0][2];
ans %= MOD;
long long tmp = n;
ans += MOD - solve(1, d, 0, 0, tmp);
ans %= MOD;
cout << ans << endl;
return 0;
}