Editorial for Technovation

Editorial for Technovation

This is an editorial for the Technovation contest. Due to less number of test cases, some brute force leads to "AC" :(

Contest Link

Problem -A

Due to lower constraints, one can solve this problem using brute force. But when the constraint is as follows

$$1 \le a, b \le 10^5$$

We should use a sieve and find all prime factors using that. Once you find the prime factors of all those two numbers after that you can simply add both and multiply. Here is the code. If you are not aware of how a sieve works be sure to read my previous article on sieves.

#include<bits/stdc++.h>
using namespace std;
#define int long long int

const int NN = 1e5 + 1;
vector<int> seive(NN);
void fseive() {
    for(int i = 0; i < NN; i++) {
        seive[i] = i;
    }


    for(int i = 2; i < NN; i++) {
        if(seive[i] == i) {
            int cur = i + i;
            while(cur < NN) {
                seive[cur] = i;
                cur += i;
            }
        }
    }
}

set<int> getPrimeFact(int num) {
    set<int> primeFact;
    int cur = num;
    while(cur != seive[cur]) {
        primeFact.insert(seive[cur]);
        cur /= seive[cur];
    }

    primeFact.insert(cur);
    return primeFact;
}

void solve() {
    int a, b;
    cin >> a >> b;

    set<int> primeFactA = getPrimeFact(a);
    set<int> primeFactB = getPrimeFact(b);

    int mulA = 0, mulB = 0;
    for(auto itr: primeFactA) {
        mulA += itr;
    }       
    for(auto itr: primeFactB) {
        mulB += itr;
    }
    cout << mulA * mulB << endl;
}

int32_t main() {
    fseive();
    int tt;
    cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}

Problem -B

You have to typical digit sum of numbers and you continue to do that until you reach a single digit. There were two similar problems with lower and higher constraints. The first one could be easily done via brute force. In this, you continue to call a digit sum function until you get a single digit. The maximum digit could be 9 so you don't have to worry about TLE.

#include<bits/stdc++.h>
using namespace std;
#define int long long int

int digitSum(int num) {
    int sum = 0;
    while(num) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

void solve() {
    int num;
    cin >> num;

    while(num >= 10) {
        num = digitSum(num);
    }
    cout << num << endl;
}

int32_t main() {
    int tt;
    cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}

Problem -C

There was just an about important observation that the sum of digits done infinitely is just the sum taken with mod 9. And if the answer is 0 at the end it will be equal to 9.

The sum of digits is done infinitely: if you take a number and take it to digit sum. And if you continue to do this until a single digit. That will be its digit sum done infinitely. Since the constraints are too huge we have to use string instead of int. In this problem

#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int kMod = 9;
void solve() {
    string s;
    cin >> s;

    int sum = 0;
    for(auto itr: s) {
        int cur = itr - '0';
        sum = (sum + cur) % kMod;
    }

    if(sum == 0) {
        sum = 9;
    }
    cout << sum << endl;
}

int32_t main() {
    solve();
    return 0;
}

Problem -D

This problem was taken from Codeforces.

An editorial from Codeforces.

Video Editorial by Erichto.

Thank You!

If you still have any doubts feel free to contact us below.