Ultraviolet A 408-Uniform Generator

Source: Internet
Author: User

This is a number topic that I figured out today. It was quite interesting. yeah came up with it for a moment. However, I had to pay for my carelessness in the tragedy three times, nm data center Blank
All cells are wrong, and I forgot to empty the lines. Clearly the string starts from 25 columns and has four spaces in the middle. I typed five spaces for nc and then pe, there are also requirements for not looking at the output carefully, no output is empty
OK. It's not in the status recently.
In fact, it is easy to figure out this question. It is also the concept of group in number theory, that is, the group generated by the addition group. It is just a fake random number. Because there is no seed limit
There is no impact on the answer. If the seed is 0, the series can be expressed as a * step. The series must be able to generate all numbers in 0-mod-1, then there is a * step = B % mod
(0 <= B <mod ).
Haha, the formula above is a * x = B % n linear homogeneous equation, but there are a lot of B. Do you need to solve the equation, not meet the condition gcd (a, n) | B?
Gcd (a, n) is an integer multiple. But 0 <= B <n, B will be 1, so gcd (a, n) must be 1. Then you can directly determine whether gcd (step, mod) is 1. Haha.
For linear homogeneous equations a * x = B % n, the conditional gcd (a, n) | B must be interpreted. For more information, see Introduction to algorithms or other materials...

The code is very simple, as follows:
# Include <stdio. h>
# Include <algorithm>
Using namespace std;

Int gcd (int a, int B)
{
If (a <B) swap (a, B );
While (B)
{
Int t =;
A = B;
B = t % B;
}
Return;
}

Int main ()
{
Int nStep, nMod;

While (scanf ("% d", & nStep, & nMod) = 2)
{
Printf ("% 10d % 10d % s \ n", nStep, nMod,
Gcd (nStep, nMod) = 1? "Good Choice": "Bad Choice ");
}

Return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.