vijayendra_ch's blog

By vijayendra_ch, history, 15 hours ago, In English

I have solved the question found the logic and wrote the code i am not asking the solution but when i just submit the code in second testcase

"wrong answer 35th numbers differ — expected: '2', found: '22'" my code would just output only one answer and it is single digit...

https://codeforces.me/contest/1476/submission/310223696

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
15 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

missing endl... in your else statement

  • »
    »
    14 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Thanks got it I kinda spent more and 90 minutes on this problem to figure out the logic and I didn't check my code properly

»
15 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

It's because you don't use endl on the else statement! Change: else cout<<(k+(n-1))/n; to: else cout<<(k+(n-1))/n<<endl;

»
13 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

try this

The issue was mainly with your last line if im not wrong or the spacing

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

void solve() {
    ll n, k;
    cin >> n >> k;
    if (k % n == 0) {
        cout << k / n << endl;
    } else if (n % k == 0) {
        cout << 1 << endl;
    } else if (n > k) {
        cout << 2 << endl;
    } else {
        cout << (k + n &mdash; 1) / n << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}