CF1928C Physical Education Lesson

原题链接

先考虑暴力枚举每个 k 是否合法,发现 k 合法当且仅当 (2k2)(nx) 或者 (2k2)(n+x2) 并且 kx。因为当 n 处于每一段中的第 1k 个数中时 nx 是上一段的结尾,n 处于每一段中的第 k2k2 个数中时 n+(x2) 是这一段的结尾。

所以直接枚举 nxn+(x2) 的因数 p,要保证 2p 并且 p+22x。注意可能有重复的,可以用 set 去重。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
using namespace std;
int T,x,n;set <int> s;
inline void A(int y)
    {if(!(y&1)&&y/2+1>=x) s.insert(y);}
inline void work()
{
    cin>>n>>x;
    int a=n-x,b=n+(x-2);
    for(int i=1;i<=sqrt(a);++i)
        if(!(a%i)) A(i),A(a/i);
    for(int i=1;i<=sqrt(b);++i)
        if(!(b%i)) A(i),A(b/i);
    cout<<s.size()<<'\n';s.clear();
}
int main()
{
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(0);
    cin>>T;while(T--) work();
    return 0;
}
posted @   int_R  阅读(46)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示