Codeforces 1485C Floor and Mod (枚举)

简介: Codeforces 1485C Floor and Mod (枚举)

原题链接

思路:

ba=amodb=k

那么显然k是小于b的。

a=kb+k=k(b+1)

k2<k(b+1)=ax

1kx,k

接下来只需枚举k,看有多少对符合的数即可。

整理上面的条件可得:

b>k

1by

1k(b+1)x=>1bkx1

这样枚举的时候,对于每一个k,b和k的值确定了,a的值也就确定了。所以答案就等于枚举的时候b的取值方案数求和,即:

k=1xmax(0,min(y,kx1)k

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
#define I_int ll
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const int maxn=1e6+7;
void solve(){
  ll x=read(),y=read();
  ll res=0;
  for(ll k=1;k*k<=x;k++)
    res=res+max(0ll,min(y,x/k-1)-k);
  printf("%lld\n",res);
}
int main(){
  int T=read();
  while(T--) solve(); 
  return 0;
}

参考:官方题解

目录
相关文章
|
9月前
|
机器学习/深度学习 人工智能 vr&ar
A. Mocha and Math(codeforces#738(div2))
A. Mocha and Math(codeforces#738(div2))
35 0
|
机器学习/深度学习 Java
Codeforces Round #748 (Div. 3) D2. Half of Same(数学 枚举 思维)
Codeforces Round #748 (Div. 3) D2. Half of Same(数学 枚举 思维)
85 0
codeforces446—— A.DZY Loves Sequences(DP+枚举)
codeforces446—— A.DZY Loves Sequences(DP+枚举)
68 0
codeforces446—— A.DZY Loves Sequences(DP+枚举)
Codeforces Round #747 (Div. 2) D. The Number of Imposters(扩展域并查集 带权并查集)
Codeforces Round #747 (Div. 2) D. The Number of Imposters(扩展域并查集 带权并查集)
99 0
|
人工智能
Codeforces1343D - Constant Palindrome Sum + UPC-鸭子游戏 (差分)
Codeforces1343D - Constant Palindrome Sum + UPC-鸭子游戏 (差分)
78 1
|
人工智能 BI
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
CodeForces - 1485D Multiples and Power Differences (构造+lcm)
62 0

热门文章

最新文章