BUGCAL - Editorial




Author: Trung Nguyen

Tester: Oleksandr Kulkov

Editorialist: Oleksandr Kulkov






You’re given two numbers. Sum them up without carrying.


Just do what is written in statement.


One of possible codes to solve the problem:

    int a, b;
    cin >> a >> b;
    vector<int> A, B;
    while(a) {
        A.push_back(a % 10);
        a /= 10;
    while(b) {
        B.push_back(b % 10);
        b /= 10;
    while(A.size() < B.size()) A.push_back(0);
    while(B.size() < A.size()) B.push_back(0);
    for(int i = 0; i < A.size(); i++) {
        A[i] += B[i];
    int ans = 0;
    reverse(begin(A), end(A));
    for(auto it: A) {
        ans = ans * 10 + it % 10;
    cout << ans << endl;


Author’s solution can be found here.

Tester’s solution can be found here.


1 Like

Love the quick explanation :stuck_out_tongue:

1 Like

We can just find the actual sum and keep subtracting 10,100,1000… from it by looping the original numbers till the number with less number of digits gets exhausted(we subtract only if we get a carry from the previous place value).

Here is the link to my solution:- My Solution

There is a typo below PROBLEM. It should be “Sum them up without carrying.”

I wanted to comment and not post an answer, but I couldn’t find a comment button. I am new here and couldn’t locate the comment button. Please help.


Nevermind, I found it below my answer under more option. I think we have to first post an answer and then we can convert it to comment below question or someone’s answer. And yeah BTW the links for author’s solution and Tester’s solution aren’t working.

There is a comment button but it will be available when you have at least 50 karma. Also thanks for pointing out, I’ll correct the typo :slight_smile:

@meooow But I can still make my answer as comment. Then what difference will it make when I get 50 points?

And what about the solution links not working?

If you really can convert your answer to a comment that’s a bug, not a feature :stuck_out_tongue:
About the solution links, it’s not under my control but I am letting the admins know.

Let me check by posting an answer if that option really works.

It really works…!!

Haha, well good then. Also the solution links are working now.

Thank you. And BTW Should I report this bug to codechef? Are you sure users with less than 50 Karma points can’t comment?

@meooow I have mailed to bugs@codechef.com about this. Lets see what they have to say about it and What is the outcome.

Its a known issue. Dont worry. BTW, you shouldnt actually do that if you want to be away for trouble. Word is, that one of the mods is reallllllyyyy strict.

@vijju123 I wasn’t exploiting the bug. I just came to know about it and I tested it only once for surety. I reported it immediately when I was sure about it. I am sorry if I offended someone or made someone angry, but I meant no harm.

Here is my approach to this problem ::


Could not pass the subtask 2:

#include <iostream>
#define ll long long int
using namespace std;

int main()
 ll t;
    string a, b;
    ll max_last = max(a.size(), b.size());
    ll min_last = min(a.size(), b.size());
    ll result[max_last];
    ll i=max_last-1;
    for(ll  j= min_last-1; j>=0; i--, j--){
        ll sum = a[i]-'0' + b[j]-'0';
        result[i] = sum ;
        result[i] = a[i]-'0';

    ll sum = 0;
    for(ll i=0; i<max_last; i++)
        sum = sum*10 + result[i]%10;
  return 0;

In your first loop, you can’t be sure that i applies to a[] andj applies to b[].