Digit Sum Parities || April Cook-Off 2022 Editorial

Here Below I written my Solution of Digit Sum Parities in Two different Languages C++ and Python.

Solution in C++ :

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

ll digitsum(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

int main()
{
	ll t = 1;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		ll sum = 0;
		ll temp = n;
		while (temp)
		{
			sum += temp % 10;
			temp /= 10;
		}
		bool flag = true;
		while (flag)
		{
			n += 1;
			ll s = digitsum(n);
			if (s % 2 != sum % 2)
			{
				cout << n << "\n";
				flag = false;
				break;
			}
		}
	}
}

Solution in Python3 :

def digitsum(x):
    sum = 0
    while x != 0:
        sum += x % 10
        x = x // 10
    return sum

t = int(input())
for _ in range(0,t):

    n = int(input())

    num1 = digitsum(n)
    num2 = digitsum(n+1)
    if (num1 % 2 != num2 % 2):
        print(n+1)
    else:
        print(n+2)