procedure cube(a,b,c,d,e:real); Var p,q,delta,phi,i:real; y:array[1..3] of real; begin p:=(3*a*c-sqr(b))/(3*sqr(a)); q:=(2*power(b,3)-9*a*b*c+27*sqr(a)*d)/(27*power(a,3)); delta:=power(q/2,2)+power(p/3,3); if delta<0 then begin if q<0 then phi:=arctan(sqrt(-delta)/(-q/2)); if q>0 then phi:=arctan(sqrt(-delta)/(-q/2))+pi; if q=0 then phi:=pi/2; y[1]:=2*sqrt(-p/3)*cos(phi/3); y[2]:=2*sqrt(-p/3)*cos(phi/3+(2*pi)/3); y[3]:=2*sqrt(-p/3)*cos(phi/3+(4*pi)/3); var x:=seq(y[1]-b/(3*a),y[2]-b/(3*a),y[3]-b/(3*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; if delta>0 then begin var arsom:=range(0,1000).Where(x->(a*power(x,3)+b*x*x+c*x+d)/(x-e)=0); write(arsom.Count); {Мы не виноваты, Паскаль не может в комплексные числа} end; if delta=0 then begin y[1]:=2*power(-q/2,1/3); y[2]:=-power(-q/2,1/3); var x:=seq(y[1]-b/(3*a),y[2]-b/(3*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; end;
procedure square(a,b,c,e:real); Var d:real; begin d:=sqr(b)-4*a*c; if d<0 then writeln('0'); if d>0 then begin var x:=arr((-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; if d=0 then begin var x:=arr(-b/(2*a)); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end; end;
procedure common(a,b,e:real); begin var x:=arr(-b/a); write(x.where(x -> x<>e).where(x -> frac(x)=0).where(x -> x>=0).Where(x -> x<=1000).Distinct.Count); end;
procedure awfulvar(e:real); begin if (e>=0) and (e<=1000) then writeln('1000') else writeln('1001'); end;
procedure otherawfulvar(e:real); begin if e<>0 then writeln('1') else writeln('0'); end;
begin read(a,b,c,d,e); if (a<>0) and (b<>0) then cube(a,b,c,d,e); if (a=0) and (b<>0) then square(b,c,d,e); if (a=0) and (b=0) and (c<>0) and (d<>0) then common(c,d,e); if (a=0) and (b=0) and (c=0) and (d=0) then awfulvar(e); if (a=0) and (b=0) and (c<>0) and (d=0) then otherawfulvar(e); if (a=0) and (b=0) and (c=0) and (d<>0) then writeln('0'); end.
Ну, поскольку уточнения по задаче не получил, буду считать, что цифра 1 может встречаться ровно два раза в КАЖДОЙ комбинаций (в противном случае ответ, конечно, будет другой):
Всего используется 4 знака.Нормализуем последовательность к нулю , от этого количество комбинаций не изменится: было : 111111 - 44444 стало: 00000 - 33333
Исключаем из общего количества комбинаций комбинации с двумя единицами (всего 9): 11ххх 1х1хх 1хх1х 1ххх1 х11хх х1х1х х1хх1 хх11х хх1х1 ххх11 значимыми остаются только 3 разряда из 5. 333 в 4-ричной системе счиления равно 63 в 10-ричной. - именно столько комбинаций будет при условии, что два разряда выставлены в единицы. 9х63=563 - столько комбинаций будет всего.
#include <iostream>
#include <vector>
#include <numeric>
#include <random>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace std;
namespace ublas = boost::numeric::ublas;
void fill_matrix (ublas::matrix<int> & A)
{
random_device rng;
uniform_int_distribution<> gen (-10, 10);
for (int i = 0; i < A.size1(); i++)
for (int j = 0; j < A.size2(); j++)
A(i,j) = gen(rng);
}
int addition (int current_sum, int value)
{
if (value < 0 && value&1)
return current_sum + value;
return current_sum;
}
int main()
{
int n = 4;
ublas::matrix<int> A (n, n);
fill_matrix (A);
cout <<A <<endl;
int sum = accumulate (A.begin2(), A.end2() + A.size2() * (A.size1() - 1), 0,
addition);
cout <<sum <<endl;
}