Codeforces Round #701 (Div. 2) C. Floor and Mod(数学推导)

本文介绍了数学竞赛中的一道题目,涉及到整数除法的地板值与余数的关系。通过转换表达式,得出a = k + bk,其中k为a除以b的余数。进一步分析,得出b的范围限制,并给出解决此类问题的枚举方法。最终提供了一个C++代码实现,用于求解在给定a和b的范围内,满足条件的组合数量。
摘要由CSDN通过智能技术生成

C. Floor and Mod

题意:

给你一个式子 ⌊ a b ⌋ \lfloor \frac{a}{b}\rfloor ba = a%b。之后再给你两个范围来限制a和b。
问最多有几对组合。

思路:

首先对于a%b,我们可以进行下转换。(主要是翻译下题目条件

  1. a%b = a - ⌊ a b ⌋ ∗ b \lfloor \frac{a}{b} \rfloor * b bab
  2. 对于题目 的要求 ⌊ a b ⌋ \lfloor \frac{a}{b}\rfloor ba = a%b
  3. 我们另 k = ⌊ a b ⌋ \lfloor \frac{a}{b}\rfloor ba = a%b
  4. 那么1式 就转换成了 a = k+bk

更加一般地,k在3式中,其实就是代表a%b( ⌊ a b ⌋ \lfloor \frac{a}{b}\rfloor ba)的结果。

那么我们可以由此得到启发,来枚举k(枚举所有可能的余数)

通过观察样例,可以发现b>k

再结合4式有: x ≥ k 2 x\ge k^2 xk2 x ≥ a = k + b k > k 2 x\ge a=k+bk > k^2 xa=k+bk>k2
(第一个式子是限制枚举k的范围,第二个式子是后面用)

由上式确定b的范围 b ≤ x k − 1 b \le \frac{x}{k} -1 bkx1
再结合题意有 1 ≤ b ≤ y 1\le b\le y 1by

最后每次枚举ans+= m a x ( 0 , m i n ( y , x / k − 1 ) − k ) max(0,min(y,x/k−1)−k) max(0,min(y,x/k1)k).

AC

/*
皮卡丘冲鸭!
へ     /|
  /\7    ∠_/
  / │   / /
 │ Z _,< /   /`ヽ
 │     ヽ   /  〉
  Y     `  /  /
 イ● 、 ●  ⊂⊃〈  /
 ()  へ    | \〈
  >ー 、_  ィ  │ //
  / へ   / ノ<| \\
  ヽ_ノ  (_/  │//
  7       |/
  >―r ̄ ̄`ー―_
*/
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define ALL(x) x.begin(),x.end()
#define mp make_pair
#define fi first
#define se second
#define db double
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
typedef pair<db,db> pdd;

const int N = 2e5+10;
const int M = 1e5;
const int maxn=1e6+10;
const db eps = 1e-8;
const db pi = acos(-1.0);

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll tt;
    cin>>tt;
    while(tt--){
        ll x, y;
        cin>>x>>y;
        ll ans = 0;
        for(int i = 1; i*i<=x; i ++ ){
            ll r = min(y,x/i-1);
            ans += max((LL)0,r-i);
        }
        cout<<ans<<'\n';
    }
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值