UFO lifting device

 

Title Description

wjyyy when playing KartRider, access to a UFO lifting device, so that he can slow down interference from a flying saucer.
UFO release means the end of the second attack will be a flying saucer, but the probability that only p / q successful attack UFO. When a UFO is a successful attack, the deceleration state is released.
If the attack fails, the UFO will wjyyy average speed becomes 1 / k times before the second.
wjyyy started at a speed vm / s traveling, Q results in deceleration state is released, a desired travel distance of his modulo 998,244,353.

Entry

Input common line, a total of four non-negative integer k, p, q, v. Wherein gcd (p, q) = 1.

Export

The output common line, represents the results of running a desired wjyyy 998244353 modulo distance.

Sample input

2 2 3 9

Sample Output

119789331

prompt

To 100% of the data, gcd (p, q) = 1,1≤k≤998244352,1≤p≤q≤998244352,0≤v≤998244352
prompt wjyyy first second distance traveled is vm, if he this when no attack is successful, the second after the second traveled distance 2 × v / km.
And so on.

 Ideas:

Note that the deceleration after the failure of the attack is the overall average speed (including the total of the whole process before the journey) down to v / k 

It is desirable to: v (p / q) + 2v (p / q) (1-p / q) / k + 3v (p / q) ((1-p / q) / k) ^ 2 + ......

I.e. n tends to seek the first n Infinite number of columns and the ratio error by calculating the phase displacement Save Sn = a1 * (1 - Q ^ n) / (1-Q) ^ 2

As n tends to infinity Q <1 so that Sn = a1 / (1-Q) ^ 2

Where a1 = p / q * v, Q = (1 - p / q) / k (note inverse element)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const ll mod=998244353;
 5 
 6 ll pow1(ll a,ll b) {
 7     ll res = 1;
 8     while (b) {
 9         if (b & 1) {
10             res = res * a % mod;
11         }
12         b >>= 1;
13         a = a * a % mod;
14     }
15     return res;
16 }
17 
18 ll inv(ll x){
19     return pow1(x,mod-2);
20 }
21 
22 ll k,p,q,v;
23 int main() {
24     scanf("%lld%lld%lld%lld", &k, &p, &q, &v);
25     ll a = p * inv(q) % mod * v % mod;
26     ll Q = ((1 - p * inv(q)+mod) % mod) % mod * inv(k) % mod;
27     ll ans = a * inv(1-Q) % mod * inv(1-Q) % mod;
28     printf("%lld\n", ans);
29 }
View Code

 

Guess you like

Origin www.cnblogs.com/Accpted/p/11203971.html