Official

B - Hard Calculation Editorial by en_translator


If, for every non-negative integer \(n\), the sum of “\(10^n\)’s place of \(A\)” and “\(10^n\)’s place of \(B\)” is \(9\) or less, then there will be no carries.
Conversely, if there exists a non-negative integer \(n\) such that the sum of “\(10^n\)’s place of \(A\)” and “\(10^n\)’s place of \(B\)” is \(10\) or more, then there will be a carry.
One of the easiest implementation is to check in order, the least significant digits first. Specifically, we apply the following algorithm.

  1. Find the sum of the remainder of \(A\) divided by \(10\) and the remainder of \(B\) divided by \(10\). If this is more than or equal to \(10\), then there will be a carry, so print Hard and exit.
  2. Divide \(A\) and \(B\) by \(10\), respectively (with the fractional parts rounded down).
  3. Repeat the operations 1 and 2 until either \(A\) or \(B\) becomes \(0\). If no carry has been detected, then there will be no carry, so print Easy and exit.

Sample code (C++)

#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b;
  cin >> a >> b;
  while(a>0 && b>0){
    if((a%10)+(b%10)>=10){cout << "Hard\n";return 0;}
    a/=10;b/=10;
  }
  cout << "Easy\n";
}

posted:
last update: