結果

問題 No.2259 Gas Station
ユーザー Josue Huaroto (HeNeos)Josue Huaroto (HeNeos)
提出日時 2023-04-08 01:54:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,004 bytes
コンパイル時間 3,632 ms
コンパイル使用メモリ 194,384 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-12 10:41:42
合計ジャッジ時間 3,538 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000
#define N 1005
using ll = long long;

ll fastexp(ll x, ll y, ll p){
	ll ans = 1;
	while(y > 0){
		if(y&1) ans = (ans*x)%p;
		y = y>>1;
		x = (x*x)%p;
	}
	return ans%p;
}

ll inv(ll x, ll p){
	return fastexp(x, p-2, p);
}

int phi[N];
void cphi(){
	phi[1] = 1;
	for(int i=2; i<N; i++){
		if(!phi[i]){
			phi[i] = i-1;
			for(ll j=2*i; j<N; j+=i){
				if(phi[j] == 0) phi[j] = j;
				phi[j] = phi[j]/i*(i-1);
			}
		}
	}
}

int l, r;

int solve(int c, int m){
	int g = __gcd(c, MOD);
	if(m%g != 0) return -1;
	c /= g;
	m /= g;
	ll x = (1LL*m*fastexp(c, phi[MOD/g]-1, MOD/g))%(MOD/g);
	if(x == 0) x+=MOD/g;
	int k = l/(MOD/g);
	if(x + (MOD/g)*k >= l and x + (MOD/g)*k <= r){
		return x+(MOD/g)*k;
	}
	else return -1;
}


int main(){
	cphi();
	int c; cin >> l >> r >> c;
	for(int m=1000; m>0; m--){
		int x = solve(c, m%MOD);
		if(x != -1){
			cout << MOD-m << '\n';
			return 0;
		}
		// l*l1+l%1000 <= x+1000*k <= r*r1 + r%1000
	}
	return 0;
}
0