This repository has been archived on 2023-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_cpp/seminar02_encapsulation/homework/code/1number/main.cpp

78 lines
1.9 KiB
C++
Raw Normal View History

2022-09-14 19:05:27 +03:00
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
2022-09-15 08:40:48 +03:00
#include "number.h"
2022-09-14 19:05:27 +03:00
Number fib(int n) {
Number a = 0; // F0
Number b = 1; // F1
for (int i = 1; i <=n; ++i) {
if (i % 2) {
a += b;
}
else {
b += a;
}
}
if (n % 2) {
return b;
}
return a;
}
Number factorial(int n) {
Number result{1};
for (int i = 2; i < n + 1; ++i) {
result = Number(i) * result;
}
return result;
}
2022-09-15 08:21:25 +03:00
void grad(Number n) {
std::cout << "n = " << n;
Number max = n;
unsigned long long int steps = 0;
while (n != Number(1)) {
if (n > max) {
#ifdef _DEBUG_COMP
std::cout << n << " is greater than " << max << std::endl;
#endif
max = n;
}
if (n.isEven()) {
n.div2();
}
else {
n = Number(3) * n + Number(1);
}
2022-09-15 08:40:48 +03:00
#ifdef _DEBUG_GRAD
if(steps > 100) {
std::cout << "break" << std::endl;
break;
}
#endif
2022-09-15 08:21:25 +03:00
++steps;
}
std::cout << " steps = " << steps << " max = " << max << std::endl;
}
2022-09-14 19:05:27 +03:00
int main()
{
2022-09-15 08:40:48 +03:00
std::cout << fib(1000) << std::endl;
2022-09-14 19:05:27 +03:00
//x = x * Number(24)*Number{25};
//y = factorial(5);
//std::cout << x << " " << x.capacity << " " << x.size << std::endl;
//std::cout << y << " "<< y.capacity << " " << y.size << std::endl;
//std::cout << "===" << std::endl << Number(2) * Number(3) << " "<< Number(3) * Number(2) << std::endl;
//std::cout << "5! = " << Number(2) * Number(3) * Number(4) * Number(5) << std::endl;
2022-09-15 08:21:25 +03:00
//std::cout << factorial(1000) << std::endl;
2022-09-14 19:05:27 +03:00
//std::cout << Number("620448401733239439360000") * Number(25) << std::endl;
2022-09-15 08:21:25 +03:00
//std::cout << (y < x) << std::endl;
2022-09-15 08:40:48 +03:00
//grad(Number("4761963248413673697"));
2022-09-15 08:21:25 +03:00
//grad(Number("256"));
//std::cout << Number(128) * Number(3) + Number(1) + Number(2) + Number(3) + Number(4) << std::endl;
2022-09-14 19:05:27 +03:00
}