Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- class Generator {
- std::vector<int64_t> ratios, elements;
- int64_t current_number;
- public:
- Generator(std::vector<int64_t> input_ratio, std::vector<int64_t> input_elem)
- : ratios(input_ratio), elements(input_elem) {}
- int64_t getNextValue() {
- int64_t temp = current_number;
- current_number = (ratios[0] * elements[2] + ratios[1] * elements[1] +
- ratios[2] * elements[0]) % ratios[3];
- elements[0] = elements[1], elements[1] = elements[2],
- elements[2] = current_number;
- return current_number;
- }
- bool operator==(Generator& object) {
- return elements[0] == object.elements[0] &&
- elements[1] == object.elements[1] && elements[2] == object.elements[2];
- }
- bool operator!=(Generator& object) {
- return !(object == *this);
- }
- };
- class Analyzer {
- std::vector<int64_t> ratios, elements;
- public:
- Analyzer(std::vector<int64_t> input_ratio,
- std::vector<int64_t> input_elem) :
- ratios(input_ratio), elements(input_elem) {}
- int64_t FindPeriod() {
- Generator turtle(ratios, elements), ahill(ratios, elements);
- turtle.getNextValue();
- while (turtle != ahill) {
- turtle.getNextValue();
- turtle.getNextValue();
- ahill.getNextValue();
- }
- turtle.getNextValue();
- int64_t period = 1;
- while (turtle != ahill) {
- turtle.getNextValue();
- ++period;
- }
- return period;
- }
- int64_t FindPrePeriod(uint64_t period) {
- Generator start_generator(ratios, elements),
- next_generator(ratios, elements);
- for (uint64_t i = 0; i < period; ++i) {
- next_generator.getNextValue();
- }
- uint64_t n = 0;
- while (next_generator != start_generator) {
- next_generator.getNextValue();
- start_generator.getNextValue();
- ++n;
- }
- return n;
- }
- long double getGoodness() {
- std::vector<long double> res(400, 0.0);
- Generator gen(ratios, elements);
- std::vector<int64_t> counts(20, 0);
- for (int i = 0; i < counts.size(); ++i) {
- long double new_number = gen.getNextValue() * 1.0 / ratios.back();
- ++counts[std::trunc(new_number * 20.0)];
- }
- long double ans = 0.0l;
- for (int i = 0; i < counts.size(); ++i) {
- ans += ((counts[i] - 20) * (counts[i] - 20)) / 400.0;
- }
- ans = std::sqrt(ans);
- return ans;
- }
- };
- int main() {
- int64_t a, b, c, d, x0, x1, x2;
- std::cin >> a >> b >> c >> d >> x0 >> x1 >> x2;
- Analyzer analyzer({a, b, c, d}, {x0, x1, x2});
- auto p = analyzer.FindPeriod();
- std::cout << p << "\n";
- std::cout << analyzer.FindPrePeriod(p) << "\n" << analyzer.getGoodness();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement