Submission details
Task:Counting ones
Sender:aalto26hh_038
Submission time:2026-10-27 18:21:14 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:32:32: warning: for increment expression has no effect [-Wunused-value]
   32 |         for (int j = i + 1;; j < n; j++)
      |                              ~~^~~
input/code.cpp:32:35: error: expected ')' before ';' token
   32 |         for (int j = i + 1;; j < n; j++)
      |             ~                     ^
      |                                   )
input/code.cpp:32:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   32 |         for (int j = i + 1;; j < n; j++)
      |         ^~~
input/code.cpp:32:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   32 |         for (int j = i + 1;; j < n; j++)
      |                                     ^
input/code.cpp:32:37: error: 'j' was not declared in this scope

Code

#include <iostream>
#include <vector>

using namespace std;

int bitCount(long long a){
    int count = 0;
    while (a > 0){
        count += (a & 1); // Mask
        a >>= 1;
    }

    return count;
}

int main(){
    int n;
    cin >> n;

    vector<long long> numbers(n);
    for (int i = 0; i < n; i++)
    {
        cin >> numbers[i];
    }
    
    int found_max = -1;
    long long val1 = -1;
    long long val2 = -1;

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1;; j < n; j++)
        {
            long long result = numbers[i] * numbers[j];
            int ones = bitCount(result);

            if (found_max < ones)
            {
                found_max = ones;
                val1 = numbers[i];
                val2 = numbers[j];
            }
            

        }
        
    }
    
    cout << found_max << "\n";
    cout << val1 << " " << val2 << "\n";

    return 0;
}