#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool rcmp(int a, int b) { return a>b; } typedef long long LL; class mypcmp { public: bool operator()(const int& a, const int& b) { return aa) printf("0\n"); else if (k==a) { m -= m%a; r = m/a-m/b-1+m/v; printf("%lld\n", r); } else { if (k%g) printf("0\n"); else { y=-y; // x*a-y*b = g x*=(k/g); y*=(k/g); // x*a-y*b = k fa=b/g; fb=a/g; cx=x/fa; x-=cx*fa; y-=cx*fb; while (x<=0) { x+=fa; y+=fb; } while (y<=0) { x+=fa; y+=fb; } r=m/a-x; if (r<0) r=0; else { r = r/fa+1; } // printf("%lld*%lld-%lld*%lld=%lld --> %lld\n", x, a, y, b, k, r); x=-x; y=-y; while (x<=0) { x+=fa; y+=fb; } while (y<=0) { x+=fa; y+=fb; } t = m/b-y; if (t<0) t=0; else t = t/fb+1; // printf("%lld*%lld-%lld*%lld=-%lld --> %lld\n", x, a, y, b, k, t); r+=t; printf("%lld\n", r); } } } return 0; }