Home > Back-end >  C language for the number
C language for the number

Time:09-27

C 4 are given by an int, all within 100, x0, a, b, m

Then according to the following formula to calculate the number 100 in turn:

X1=\ mod m (ax0 + b)

X2=\ mod m (ax1 + b)

Asked whether the 100 number, appear most times is how much? If there are multiple answers, output value, the youngest

For example, the input is: 1 and 2

The x calculation sequence is in turn: 0,1,0,1,?

So 1 s and 0 s in 50 times, the output should be: 0

The prototype of this is actually a pseudo random number, when we select a, b, m, given different x0, can get different sequence, and the number in this sequence can be thought of in [0, m) is evenly distributed, of course, if m is small, obviously it is easy to repeat,

Can make use of mathematical knowledge, of course, the formula is derived, under the given initial conditions, which is the numerical calculated appear most times a,

But in the case of the relatively small size, with computer simulation directly again is also very good,

How do you know the numerical there have been many times v? Very simple, use a counter CNT arrays [], place whenever v, + + [v] can, CNT,

CodePudding user response:

May be able to use an array, but what is the code

CodePudding user response:

refer to the second floor qq320277 response:
may be able to use an array, but what does this code is

Yes, your code?
  • Related