Help me in solving CHFINVNT problem

My issue

Anyone can check my code why some test case are not passing .

My code

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int N,K,P;
	    cin>>N>>P>>K;
	    int r=P%K;
	    int move=ceil(N/(float)K);
	    int ans=r*move;
	    ans+=(P-r)/K+1;
	    cout<<ans<<endl;
	}
	return 0;
}

Problem Link: CHFINVNT Problem - CodeChef

@mohdkaif123
for test case
1
4 2 3
your code prints
5
and answer should be 4

could you please find why below code shows runtime error:
include <bits/stdc++.h>
define ll long long
using namespace std;

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
if (a.first == b.first) {
return a.second < b.second;
}
return a.first < b.first;
}

void solve() {
ll n, p, k;
cin >> n >> p >> k;

vector<pair<ll, ll>> v;

for (int i = 0; i < n; i++) {
    v.push_back({i % k, i});
}



sort(v.begin(), v.end(), cmp);

ll count = 0;

for (ll i = 0; i < n; i++) {
    count++;

    if (v[i].second == p) {
        cout << count << endl;
        return;  // Terminate the loop once the answer is found
    }
}

}

int main() {
int t;
cin >> t;
while (t–) {
solve();
}

return 0;

}