UVa10633 Rare Easy Problem

http://uva.onlinejudge.org/external/106/10633.html

問題概要
2桁以上の整数Nと、Nの下一桁を取り除いた整数Mが与えられる。N-M の値があなたに伝えられるので、もとのNの候補を昇順ソートして全て示せ。

解法

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

int main() {
  ull X; // X = N-M
  
  while(cin >> X && X) {
    vector<ull> ans;
    ull N1 = X*10/9;
    ull M1 = N1/10; // cut off the last digit
    if(N1-M1 == X) ans.push_back(N1); // Evaluation 9*N1 == 10*X is not applied.
    for(ull i=1; ; i++) {
      ull Ncand = N1 + i, Mcand = Ncand/10;
      if(Ncand-Mcand == X) ans.push_back(Ncand);
      else break;
    }
    for(ull i=1; ; i++) {
      ull Ncand = N1 - i, Mcand = Ncand/10;
      if(Ncand-Mcand == X) ans.push_back(Ncand);
      else break;
    }
    
    sort(ans.begin(), ans.end());
    
    for(ull i=0; i<ans.size(); i++) {
      if(i) cout << ' ';
      cout << ans[i];
    }
    cout << endl;
  }
  
  return 0;
}