2 条题解
-
1蔡原天 (2022tysc0158) LV 3 @ 2023-4-30 22:20:08
#include<iostream> #include<cstdio> #define int long long using namespace std; int n,m,len,a,b,vis[1000001],t,ans; void find(int x){ for(int i=1;i*i<=x;i++){ if(x%i==0){ vis[++len]=i; if(i*i!=x)vis[++len]=x/i; } } } bool check(int x){ if((b-a)/x+1>n)return false; if((a-1)/x+(b-a)/x+1+(m-b)/x>=n)return true; return false; } signed main(){ scanf("%lld",&t); for(int i=1;i<=t;i++){ scanf("%lld%lld%lld%lld",&n,&m,&a,&b); if(a>b)swap(a,b); ans=len=0; find(b-a); for(int j=1;j<=len;j++)if(check(vis[j]))ans++; printf("%lld\n",ans); } } /* n=4,m=16,a=2,b=8; ***~~~a~~~~~~~~~~~b~~~~~~~~~~~~~~~m *** - 2 - - - - - 8 - - - - - - - 16 ***|-|-----------|-|---------------| *** | | | | *** | | | | ***\|/ | \|/ | ***(a-1)/x \|/ 1 \|/ *** (b-a)/x (m-b)/x */
-
-12023-4-30 17:56:10@
#include<bits/stdc++.h> #include<algorithm> #include<bitset> #include<cctype> #include<cerrno> #include<clocale> #include<cmath> #include<complex> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<deque> #include<exception> #include<fstream> #include<functional> #include<limits> #include<list> #include<map> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<utility> #include<vector> #include<cwchar> #include<cwctype> using namespace std; #define int long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; int n, m, len, a, b,vis[N]; void find(int x){ len = 0; for(int i = 1;i * i <= x;i++){ if(x % i == 0){ vis[++len] = i; if(i * i != x) vis[++len] = x / i; } } } signed main(){ int t; cin >> t; while(t--){ cin >> n >> m >> a >> b; if(a > b) swap(a,b); find(b - a); long long ans = 0; for(int i = 1;i <= len; i++){ int d = vis[i]; if((b - a) / d + 1 <= n && (a - 1) / d + (b - a) / d + (m - b) / d + 1 >= n) ++ans; } cout << ans << endl; } return 0; } //打了好久,手费(第28道今天刷的题了)ε(┬┬﹏┬┬)3
- 1
信息
- ID
- 2950
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 488
- 已通过
- 28
- 上传者