NC252839. Hide and Seek
描述
输入描述
The first line contains two integers , representing the number of constraints and the upper bound of hidden integer .
For the following lines, each line contains two integers , represents .
输出描述
A single line contains an integer, representing the number of positive integers which can suit all given constraints.
示例1
输入:
2 10 7 1 8 2
输出:
2
C++(clang++ 11.0.1) 解法, 执行用时: 66ms, 内存消耗: 3996K, 提交时间: 2023-07-30 16:19:45
#include<bits/stdc++.h> using namespace std; int m,a,b,c,g,l=1,i=1,ans; int main(){ cin>>m>>a; while(m--){ scanf("%d%d",&b,&c); g=__gcd(b-c,g); l=max(l,c+1); } if(!g){ cout<<a-l+1; return 0; } for(;i*i<g;i++) if(g%i==0&&g/i<=a&&g/i>=l) ans++; cout<<ans; }
C++(g++ 7.5.0) 解法, 执行用时: 57ms, 内存消耗: 432K, 提交时间: 2023-07-09 21:03:20
#include<bits/stdc++.h> using namespace std; int m,a,b,c,gc,l=1,i=1; int main(){ cin>>m>>a; while(m--){ scanf("%d%d",&b,&c); gc=__gcd(b-c,gc); l=max(l,c+1); } for(;i*i<gc;i++) if(gc%i==0&&gc/i<=a&&gc/i>=l) m++; cout<<(gc?++m:a-l+1); return 0; }