[boris@fedora26workstation VK]$ cat div26.cpp
#include <iostream>
using namespace std;
int main(){
int k2, k13, k26, a, n, k;
cout << "Please set length of array" << endl;
cin >> n;
cout << "Length was set = " << n << endl;
k2 =0;
k13 = 0;
k26 = 0;
k = 0;
for (int i = 1; i <= n; i++){
cin >> a ;
if (a % 26 == 0)
{
k26++;
//cout << "k26 = " << k26 << endl;
}
else if (a % 13 == 0)
{
k13++ ;
//cout << "k13 = " << k13 << endl;
}
else if (a % 2 == 0)
{
k2++;
//cout << "k2 = " << k2 << endl;
}
else
{
//cout << "All three counters stay the same" << endl;
}
}
k = k13*k2 + k26*(n-k26) + (k26*(k26-1))/2 ;
cout << "Result is " << k << endl;
}
Слагаемое (k26*(k26-1))/2 есть число сочетаний из k26 по два
[boris@fedora26workstation VK]$ ./div26
Please set length of array
13
Length was set = 13
2
13
2
13
2
13
1
1
52
52
52
52
52
Result is 59
Tested version in Python
[boris@fedora26workstation VK]$ cat dba26.py
N = int(input())
print "Length is equal ",N
k2 = k13 = k26 = 0
for i in range(N):
a = int(input())
if a % 26 != 0:
if a % 2 == 0: k2 += 1
if a % 13 == 0: k13 += 1
else: k26 += 1
R = k2*k13 + k26*(N-k26) + (k26*(k26-1)) / 2
print "Result is equal ",R
Слагаемое (k26*(k26-1)) / 2 есть число сочетаний из k26 по два.
No comments:
Post a Comment