М
Молодежь
К
Компьютеры-и-электроника
Д
Дом-и-сад
С
Стиль-и-уход-за-собой
П
Праздники-и-традиции
Т
Транспорт
П
Путешествия
С
Семейная-жизнь
Ф
Философия-и-религия
Б
Без категории
М
Мир-работы
Х
Хобби-и-рукоделие
И
Искусство-и-развлечения
В
Взаимоотношения
З
Здоровье
К
Кулинария-и-гостеприимство
Ф
Финансы-и-бизнес
П
Питомцы-и-животные
О
Образование
О
Образование-и-коммуникации
unitolog
unitolog
26.03.2023 07:19 •  Информатика

Дан рекурсивный алгоритм:
procedure F(n: integer);
begin
writeln(n);
if n < 5 then begin
F(n+1);
F(n+2);
F(n*3)
end
end;
Найдите сумму чисел, которые будут выведены при вызове F(2).

👇
Открыть все ответы
Ответ:
nikitakondrate1
nikitakondrate1
26.03.2023
Тебя интересует левое верхнее число из матрицы \begin{pmatrix}&#10;1 & 1 \\ 1 & 1&#10;\end{pmatrix}^{12}, что, кстати, является 12 числом фибоначчи

#include <iostream>
// матрица 2 на 2// a  b// c  dtemplate< typename T = int >class matrix2{public:    T a, b, c, d;
    matrix2() : a(0), b(0), c(0), d(0)    {}    matrix2(T a, T b, T c, T d) : a(a), b(b), c(c), d(d)    {}
    matrix2 & operator *= (matrix2 & other)    {        T ta, tb, tc, td;        ta = a * other.a + b * other.c;        tb = a * other.b + b * other.d;        tc = a * other.c + c * other.d;        td = b * other.c + d * other.d;        a = ta, b = tb, c = tc, d = td;    }
    matrix2 operator * (matrix2 & other)    {        T ta, tb, tc, td;        ta = a * other.a + b * other.c;        tb = a * other.b + b * other.d;        tc = a * other.c + c * other.d;        td = b * other.c + d * other.d;        return matrix2(ta, tb, tc, td);    }
    matrix2 pow(int power)    {        matrix2 result(1, 0, 0, 1);        matrix2 cur = *this;        while (power)        {            if (power & 1)            {                power ^= 1;                result *= cur;            }            else            {                power >>= 1;                cur *= cur;            }        }        return result;    }
    void operator = (matrix2 other)    {        a = other.a;        b = other.b;        c = other.c;        d = other.d;    }
    friend std::ostream & operator << (std::ostream & ostr, matrix2 ma)    {        ostr << std::endl;        ostr << ma.a << "  " << ma.b << std::endl;        ostr << ma.c << "  " << ma.d << std::endl;        return ostr;    }
};
int main(void){    matrix2< int > m1(1, 1, 1, 0), tmp;
    const int N = 12;
    std::cout << m1.pow(N).a;
    return 0;}
4,8(19 оценок)
Ответ:
animetan200
animetan200
26.03.2023

#include <iostream>

#include <cmath>

#include <algorithm>

#pragma GCC optimize("Ofast")

#define ll long long

#define ld long double

using namespace std;

signed main() {

  ll n = 8;

  ll a[n];

  ll sum = 0;

  for(ll i = 0; i < n; i++){

      cin >> a[i];

      if(a[i] % 6 == 0 && a[i] % 4 == 0)

          sum += a[i];

  }

  cout << sum << "\n";

  n = 12;

  sum = 0;

  ll b[n];

  for(ll i = 0; i < n; i++){

      cin >> b[i];

      if(b[i] % 5 == 0)

          sum++;

  }

  cout << sum;

}

4,7(25 оценок)
Это интересно:
Новые ответы от MOGZ: Информатика
logo
Вход Регистрация
Что ты хочешь узнать?
Спроси Mozg
Открыть лучший ответ