# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335092 | 2020-12-11T06:22:52 Z | nicholask | Strange Device (APIO19_strange_device) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #define int long long #define x first #define y second using namespace std; int gcd(int a,int b){ while (b) b^=a^=b^=a%=b; return a; } signed main(){ int n,a,b; cin>>n>>a>>b; pair <int,int> p[n]; for (int i=0; i<n; i++) cin>>p[i].x>>p[i].y; if (n==1){ __int128 f=p[0].y-p[0].x+1; __int128 s=a*b/gcd(b,(b+1)%i); int op=min(f,s); cout<<op; } else { set <pair <int,int> > s; for (int i=0; i<n; i++){ for (int t=p[i].x; t<=p[i].y; t++) s.insert({(t+t/b)%a,t%b}); } cout<<s.size(); } }