1485C - Floor and Mod - CodeForces Solution


binary search brute force math number theory *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
#define ll long long int
#define pb push_back
//#define getUnique(v) {sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());}
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll binexp(ll n,ll p){ll res = 1;while (p>0){if(p&1)res=res*n;n=n*n;p>>=1;}return res;}
void solve(){
    ll x,y;cin>>x>>y;
    ll ans=0;
    for(ll k=1;k<=50000;k++){
        ll leftboundary=k+2,rightboundary=min(y+1,x/k);
        if(rightboundary>=leftboundary)
            ans+=(rightboundary-leftboundary+1);
    }
    cout<<ans<<"\n";
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif
    int t;cin>>t;
    while(t--)
        solve();
}


Comments

Submit
0 Comments
More Questions

1114A - Got Any Grapes
224B - Array
125B - Simple XML
567B - Berland National Library
431B - Shower Line
282C - XOR and OR
1582B - Luntik and Subsequences
609A - Флеш-карты
1207A - There Are Two Types Of Burgers
371C - Hamburgers
343B - Alternating Current
758B - Blown Garland
1681B - Card Trick
1592A - Gamer Hemose
493D - Vasya and Chess
1485A - Add and Divide
337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height