fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void __print(int x) {cerr << x;}
  4. void __print(long x) {cerr << x;}
  5. void __print(long long x) {cerr << x;}
  6. void __print(unsigned x) {cerr << x;}
  7. void __print(unsigned long x) {cerr << x;}
  8. void __print(unsigned long long x) {cerr << x;}
  9. void __print(float x) {cerr << x;}
  10. void __print(double x) {cerr << x;}
  11. void __print(long double x) {cerr << x;}
  12. void __print(char x) {cerr << '\'' << x << '\'';}
  13. void __print(const char *x) {cerr << '\"' << x << '\"';}
  14. void __print(const string &x) {cerr << '\"' << x << '\"';}
  15. void __print(bool x) {cerr << (x ? "true" : "false");}
  16.  
  17. template<typename T, typename V>
  18. void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  19. template<typename T>
  20. void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  21. void _print() {cerr << "]\n";}
  22. template <typename T, typename... V>
  23. void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  24. #ifndef ONLINE_JUDGE
  25. #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  26. #else
  27. #define debug(x...)
  28. #endif
  29. #define endl '\n'
  30. #define ll long long int
  31. #define vi vector<int>
  32. #define mx(a,b,c,d) max(a, max(b, max(c,d)))
  33. #define MP make_pair
  34. #define pb push_back
  35. #define ppb pop_back
  36. const int md = 1e9 + 7;
  37.  
  38. const ll INF=1e9+15;
  39. const ll NAX= 2e5+5; // change it acc tothe contraints
  40.  
  41.  
  42. void solve()
  43. {
  44. ll n;
  45. cin>>n;
  46. ll num;
  47. cin>>num;
  48. ll new_num=num;
  49. vector<ll> arr;
  50.  
  51. while(num!=0){
  52. ll temp=num%10;
  53. arr.pb(temp);
  54. num/=10;
  55. break;
  56. }
  57. // debug(arr);
  58. vector<string>numbers;
  59. string str_9=" ";
  60. for(int i=0; i<n; i++){
  61. numbers.pb("9");
  62. str_9+=numbers[i];
  63. //debug(arr,str_9, numbers);
  64. }
  65. ll num_9=stoll(str_9);
  66. if(arr[0]!=9){
  67. cout<<num_9-new_num<<endl;;
  68. return;
  69. }
  70. else{
  71. numbers.clear();
  72. string str_1=" ";
  73. ll num_1;
  74. for(int i=0; i<n-1; i++){
  75. numbers.pb("1");
  76. str_1+=numbers[i];
  77. }
  78. str_1+="2";
  79. num_1=stoll(str_1);
  80. cout<<num_1<<endl;
  81. //debug(str_1, num_1, numbers);
  82. return;
  83.  
  84. }
  85.  
  86. }
  87. int main() {
  88.  
  89. ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  90.  
  91. int tc=1;
  92. cin>>tc;
  93. for (int i=0; i<tc; i++){
  94. solve();
  95. //cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  96.  
  97. }
  98.  
  99.  
  100.  
  101. }
  102.  
  103.  
  104.  
Runtime error #stdin #stdout #stderr 0.01s 5408KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  stoll