solving maths problems

Revision en1, by farmaan_khan, 2022-11-14 20:18:07

https://codeforces.me/contest/1539/problem/A i am not able to solve the problem because of constraints the first solution is this

include <bits/stdc++.h>

define ll long long

using namespace std; void solve(){ ll n,x,t; cin>>n>>x>>t; int v[n]={0}; for(int i=1;i<n;i++) v[i]=v[i-1]+x; // for(auto i:v) cout<<i<<" "; // cout<<endl; int vv[n]={0}; for(int i=0;i<n;i++) vv[i]=v[i]+t; // for(auto i: vv ) cout<<i<<" "; // cout<<endl; ll sum=0; for(int i=0;i<n-1;i++){ ll upper1 = upper_bound(v, v+n, vv[i]) — v; sum+=upper1-i-1; } cout<<sum<<endl;

} int main() { int tc; cin>>tc; while(tc--){ solve(); } } 2.nd solution is this

include <bits/stdc++.h>

define ll long long

using namespace std; void solve(){ ll n,x,t; ll ans=(max(0ll,(n-t)/x)*(t/x))+min((n-1),t/(x-1))*(min(n,(t/x)))/2; cout<<ans<<endl;

} int main() { int tc; cin>>tc; while(tc--){ solve(); } } IN FIRST ONE IT SHOWS RUN TIME ERROR BECOZ OF CONSTRAINT AND IN 2ND IT SHOWS RANDOM NUMBER MAY BE BECAUSE OF 0LL HELP ME PLEASE!!!!1:(

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English farmaan_khan 2022-11-14 20:18:07 1170 Initial revision (published)