結果

問題 No.1648 Sum of Powers
ユーザー kwm_tkwm_t
提出日時 2021-08-14 02:55:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,916 bytes
コンパイル時間 4,026 ms
コンパイル使用メモリ 232,888 KB
実行使用メモリ 11,972 KB
最終ジャッジ日時 2024-04-15 00:31:53
合計ジャッジ時間 10,732 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 43 ms
11,648 KB
testcase_03 AC 41 ms
11,776 KB
testcase_04 AC 48 ms
11,844 KB
testcase_05 AC 43 ms
11,848 KB
testcase_06 AC 44 ms
11,840 KB
testcase_07 AC 44 ms
11,776 KB
testcase_08 AC 46 ms
11,776 KB
testcase_09 AC 44 ms
11,776 KB
testcase_10 AC 42 ms
11,904 KB
testcase_11 AC 42 ms
11,776 KB
testcase_12 AC 50 ms
11,776 KB
testcase_13 AC 45 ms
11,840 KB
testcase_14 AC 43 ms
11,776 KB
testcase_15 AC 42 ms
11,972 KB
testcase_16 AC 44 ms
11,776 KB
testcase_17 AC 47 ms
11,776 KB
testcase_18 AC 42 ms
11,844 KB
testcase_19 AC 44 ms
11,776 KB
testcase_20 AC 43 ms
11,844 KB
testcase_21 AC 44 ms
11,904 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 3 ms
6,940 KB
testcase_49 AC 43 ms
11,776 KB
testcase_50 AC 46 ms
11,904 KB
testcase_51 AC 5 ms
7,168 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 4 ms
7,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
mint pm[100001][2][2];
mint pm2[100001][2][2];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long a, b, p, q; cin >> a >> b >> p >> q;
	if (0 == b) {
		// pre clac
		vector<mint>pwa(100000 + 1), pwa2(100000 + 1);
		pwa[0] = 1; pwa2[0] = 1;
		map<int, int>mp;
		mp[0] = 0;
		mint memo = pow_mod(a, 100000, mod);//a^(10^5)
		rep(i, 100000) {
			pwa[i + 1] = pwa[i] * a;
			mp[pwa[i + 1].val()] = i + 1;
			pwa2[i + 1] = pwa2[i] * memo;
		}
		// x = 0, y = a
		// a^ n = p となる n
		// n = 10^5 * v + w;
		// v : fix
		rep(i, 100001) {
			mint aw = (mint)p * pwa2[i].inv();
			if (mp.count(aw.val())) {
				long long ans = 100000LL * i + mp[aw.val()];
				cout << ans << endl;
				return 0;
			}
		}
	}
	else {
		/*pm[0][0][0] = 1;
		pm[0][1][1] = 1;
		rep(i, 100000) {
			pm[i + 1][0][0] = pm[i][0][0] * a + pm[i][0][1];
			pm[i + 1][0][1] = pm[i][0][1] * (-b);
			pm[i + 1][1][0] = pm[i][1][0] * a + pm[i][1][1];
			pm[i + 1][1][1] = pm[i][1][0] * (-b);
		}
		mint ab = (mint)a * ((mint)b).inv();
		map<P, int>mp;
		rep(i, 100001) {
			mint np = pm[i][0][0] * 2 + pm[i][0][1] * ab;
			mint nq = pm[i][1][0] * 2 + pm[i][1][1] * ab;
			mp[{np.val(), nq.val()}] = i;
		}
		pm2[0][0][0] = 1;
		pm2[0][1][1] = 1;
		mint s, t, u, v, invdet;
		invdet = pm[100000][0][0] * pm[100000][1][1] - pm[100000][0][1] * pm[100000][1][0];
		invdet = invdet.inv();
		s = pm[100000][1][1] * invdet;
		t = pm[100000][0][1] * -1 * invdet;
		u = pm[100000][1][0] * -1 * invdet;
		v = pm[100000][0][0] * invdet;
		rep(i, 100000) {
			pm2[i + 1][0][0] = pm2[i][0][0] * s + pm2[i][0][1] * u;
			pm2[i + 1][0][1] = pm2[i][0][0] * t + pm2[i][0][1] * v;
			pm2[i + 1][1][0] = pm2[i][1][0] * s + pm2[i][1][1] * u;
			pm2[i + 1][1][1] = pm2[i][1][0] * t + pm2[i][1][1] * v;
		}
		rep(i, 100001) {
			mint np = pm2[i][0][0] * p + pm2[i][0][1] * q;
			mint nq = pm2[i][1][0] * p + pm2[i][1][1] * q;
			if (mp.count({ np.val(),nq.val() })) {
				long long ans = 100000LL * i + mp[{ np.val(), nq.val() }];
				cout << ans << endl;
				return 0;
			}
		}*/
	}
	return 0;
}
0