Требуется вычислить число a по формуле a = (k^0 + k^1 + k^2 + k^3 … + k^n ) mod pопределениеa ≡ b (mod m), b это остаток деления а на m. пример: 41 ≡ 2 (mod 13), 41 = 2 + 13*3входные данныевходные данные содержит числа n, k (1 ≤ n,k ≤ 106) и p(1 ≤ p ≤ 109). выходные данныенужно вывести одно целое число - значение a.замечание 1) [5, 2, 10000], ответ: 1 + 2 + 4 + 8 + 16 + 32 = 63 mod(10000)
Відповідь:
Ввести три числа и найти их сумму и произведение
#include <iostream>
using namespace std;
int main(){
setlocale(LC_ALL , "Rus");
int a,b,c,sum,product;
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
cout << "c: ";
cin >> c;
sum = a+b+c;
product = a * b * c;
cout << "Сума = " << sum << endl;
cout << "Произведение = " << product << endl;
return 0;
}
Ввести три числа найти их сумму произведение и среднее арифметическое#include <iostream>
using namespace std;
int main(){
setlocale(LC_ALL , "Rus");
int a,b,c,sum,product;
float average;
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
cout << "c: ";
cin >> c;
sum = a+b+c;
product = a * b * c;
average = (a+b+c) / 3.;
cout << "Сума = " << sum << endl;
cout << "Произведение = " << product << endl;
cout << "Среднее арифметическое = " << average << endl;
return 0;
}
Ввести три числа и найти наибольшее из них
#include <iostream>
using namespace std;
int main(){
setlocale(LC_ALL , "Rus");
int a,b,c,sum,product;
float average;
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
cout << "c: ";
cin >> c;
if(a > b && a > c){
cout << "Наибольшее число : " << a << endl;
}
if(b > a && b > c){
cout << "Наибольшее число : " << b << endl;
}
if(c > a && c > b){
cout << "Наибольшее число : " << c << endl;
}
return 0;
}
Ввести пять чисел и найти наибольшее из них
#include <iostream>
using namespace std;
int main(){
setlocale(LC_ALL , "Rus");
int a,b,c,d,e,sum,product;
float average;
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
cout << "c: ";
cin >> c;
cout << "d: ";
cin >> d;
cout << "e: ";
cin >> e;
if(a > b && a > c && a > d && a > e){
cout << "Наибольшее число : " << a << endl;
}
if(b > a && b > c && b > d && b > d){
cout << "Наибольшее число : " << b << endl;
}
if(c > a && c > b && c > d && c > e){
cout << "Наибольшее число : " << c << endl;
}
if(d > a && d > b && d > c && d > e){
cout << "Наибольшее число : " << d << endl;
}
if(e > a && e > b && e > c && e > d){
cout << "Наибольшее число : " << e << endl;
}
return 0;
}
using System;
class Program
{
static void Main()
{
int x1 = 2, y1 = 1;
int x2 = 6, y2 = 5;
int x3 = 10, y3 = 1;
var a = Distance(x2, y2, x3, y3);
var b = Distance(x1, y1, x3, y3);
var c = Distance(x2, y2, x1, y1);
Console.WriteLine("S = {0}", Square(a, b, c));
Console.ReadKey();
}
//растояние между точками
static double Distance(int x1, int y1, int x2, int y2)
{
return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
//формула герона
static double Square(double a, double b, double c)
{
var p = (a + b + c) / 2;
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
// теорема косинусов
static double Angle(double a, double b, double c)
{
return Math.Acos((b * b + c * c - a * a) / (2 * b * c));
}
static bool IsAcuteAngel(double alpha)
{
return alpha < Math.PI / 2;
}
}