text
stringlengths
49
983k
#include<bits/stdc++.h> using namespace std; int main() { long long t1,t2; cin >> t1 >> t2; long long a1,a2,b1,b2; cin >> a1 >> a2 >> b1 >> b2; long long p,q; if(a1>b1) { p=t1*(a1-b1); q=t2*(a2-b2); } else { p=t1*(b1-a1); q=t2*(b2-a2); } if(p+q==0) { cout << "infinity" << endl; } else if(p+q>0) { cout << 0 << endl; } else { long long ans=2*(p/(-(p+q))); if(p%(-(p+q))!=0) { ans++; } cout << ans << endl; } }
#include <bits/stdc++.h> #define MAX (ll)(1e5 + 4) #define MOD (ll)(1e9 + 7) #define INF (ll)(1e18 + 3) #define PI (double)(3.14159265) using namespace std; using ll = long long; using ld = long double; int main () { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll s = (a1 - b1) * t1, ss = (a2 - b2) * t2; if (s + ss == 0) { cout << "infinity\n"; return 0; } if (((s < 0 && ss > 0) || (ss < 0 && s > 0)) && abs (ss) > abs (s)) { ss = abs (ss), s = abs (s); ll d = abs (ss) - abs (s); cout << 2 * (s / d) + ((s % d) > 0) << "\n"; } else { cout << "0\n"; } }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll p = (b1 - a1) * t1, q = (b2 - a2) * t2; if(p + q == 0){ cout << "infinity" << endl; return 0; } ll shift = p + q; if((p > 0 && shift < 0) || (p < 0 && shift > 0)){ ll k = p / shift; k = abs(k); ll ans = 2 * k + 1; if(abs(k * shift) == abs(p)) ans--; cout << ans << endl; }else{ cout << 0 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) ll ans = 0; int main() { ll t1 , t2 ; cin >> t1 >> t2 ; ll a1 , a2 ; cin >> a1 >> a2 ; ll b1 , b2 ; cin >> b1 >> b2 ; if(a1<b1){ swap(a1,b1); swap(a2,b2); } if(a1*t1+a2*t2>b1*t1+b2*t2){ cout << 0 << endl; return 0; } if(a1*t1+a2*t2==b1*t1+b2*t2){ cout << "infinity" << endl; return 0; } ll cal=a1*t1-b1*t1; ll cal2=b1*t1+b2*t2-a1*t1-a2*t2; ll k=cal/cal2; ans=1+k*2; if(cal%cal2==0)ans--; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); ll ta,tb,af,ab,bf,bb; cin >> ta >> tb >> af >> ab >> bf >> bb; af *= ta; bf *= ta; ab *= tb; bb *= tb; if(af + ab == bf + bb){ cout << "infinity" << '\n'; } else{ if(af + ab > bf + bb){ swap(af,bf); swap(ab,bb); } if(af < bf){ cout << 0 << '\n'; } else{ ll k = (af-bf)/(bf + bb - af - ab); ll cor = k * (bf + bb - af - ab) == af - bf; cout << 2*(k + 1) - 1 - cor << '\n'; } } }
#include <bits/stdc++.h> using namespace std; long t1,t2,a1,a2,b1,b2,ans=0; int main() { cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if(a1>b1) { swap(a1,b1); swap(a2,b2); } if((t1*a1)+(t2*a2)>(t1*b1)+(t2*b2)) { ans=((b1-a1)*t1)/((a1-b1)*t1+(a2-b2)*t2)*2; if(((b1-a1)*t1)%((a1-b1)*t1+(a2-b2)*t2)!=0) ans++; } if((t1*a1)+(t2*a2)==(t1*b1)+(t2*b2)) { ans=-1; } if(ans>=0) cout << ans << endl; else cout << "infinity" << endl; }
#include <iostream> using namespace std; int T1, T2; long long A1, A2, B1, B2; int main() { cin >> T1; cin >> T2; cin >> A1; cin >> A2; cin >> B1; cin >> B2; long long C1 = A1 - B1; long long C2 = A2 - B2; long long tx = C1 * T1; long long bx = tx + C2 * T2; if (bx == 0) { cout << "infinity" << endl; return 0; } if ( !((tx > 0) ^ (bx > 0))) { cout << 0 << endl; return 0; } long long int ans = ((-tx) / bx) * 2 + 1; if ((-tx) % bx == 0) { ans--; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int64_t T1,T2,A1,A2,B1,B2; cin>>T1>>T2>>A1>>A2>>B1>>B2; int64_t A=A1-B1; int64_t B=A2-B2; if((0<A&&0<B)||(A<0&&B<0)) cout<<0<<endl; else if(A*T1+B*T2==0) cout<<"infinity"<<endl; else{ if((0<A&&0<A*T1+B*T2)||(A<0&&A*T1+B*T2<0)) cout<<0<<endl; else{ int64_t a=abs(A*T1); int64_t b=abs(A*T1+B*T2); if(a%b==0) cout<<2*(a/b)<<endl; else cout<<2*(a/b)+1<<endl; } } return 0; }
#include <iostream> using namespace std; int main(){ long long T[2], A[2], B[2]; cin >> T[0] >> T[1] >> A[0] >> A[1] >> B[0] >> B[1]; for(int i = 0; i < 2; ++i){ B[i] -= A[i]; A[i] = 0; } if(T[0]*B[0]+T[1]*B[1] == 0){ puts("infinity"); return 0; } if(B[0] < 0) B[0] *= -1, B[1] *= -1; long long t = -(T[0]*B[0]+T[1]*B[1]); if(t < 0){ cout << 0 << endl; return 0; } long long ans = 2*(T[0]*B[0]/t); if((B[0]*T[0])%t){ ++ans; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int64_t T1,T2,A1,A2,B1,B2; cin>>T1>>T2>>A1>>A2>>B1>>B2; if(T1*A1+T2*A2==T1*B1+T2*B2){ cout<<"infinity"<<endl; } else{ if(T1*A1+T2*A2<T1*B1+T2*B2){ swap(A1,B1); swap(A2,B2); } if(A1>B1){ cout<<"0"<<endl; } else{ int64_t D=T1*A1+T2*A2-(T1*B1+T2*B2); int64_t C=T1*(B1-A1); if(C%D){ cout<<(C/D)*2+1<<endl; } else{ cout<<(C/D)*2<<endl; } } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if (A1 == B1 || T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) { cout << "infinity" << endl; return 0; } if (T1 * A1 + T2 * A2 <= T1 * B1 + T2 * B2) { swap(A1, B1); swap(A2, B2); } if (B1 > A1) { ll m = T1 * (B1 - A1); cout << (m / (T1 * (A1 - B1) + T2 * (A2 - B2))) * 2 + (m % (T1 * (A1 - B1) + T2 * (A2 - B2)) != 0) << endl; } else { cout << 0 << endl; } return 0; }
#include<iostream> using namespace std; int main() { long T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if (T1*A1+T2*A2==T1*B1+T2*B2) { cout << "infinity" << endl; return 0; } long M1 = T1*A1-T1*B1, M2=T2*A2-T2*B2; if (M1+M2<0) {M1 = -M1; M2=-M2;} if (M2 > 0) cout<<(max(0L, (M2-1)/(M1+M2)-1) + max(0L, M2/(M1+M2)))<<endl; else cout<<(max(0L, (M2)/(M1+M2)-1) + max(0L, (M2+1)/(M1+M2)-1))<<endl; }
#include <bits/stdc++.h> using namespace std; #define int long long template<typename T> void fin(T a){ cout<<a<<endl; exit(0); } signed main(){ int t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2; a1-=b1;a2-=b2; if(a1>0)a1*=-1,a2*=-1; int A=t1*a1+t2*a2,B=-t1*a1; if(A<0)fin(0); if(A==0)fin("infinity"); int ans=B/A*2+1; if(B%A==0)ans--; cout<<ans<<endl; } /* あまりがある時 (B/A*2+1) あまりがない時 (B/A*2) */
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,a,b,c,d,A,B; int main(void){ cin>>n>>m>>a>>b>>c>>d; if((a-c)>0&&(b-d)>0){ cout<<0<<endl; return 0; } if((a-c)<0&&(b-d)<0){ cout<<0<<endl; return 0; } A=abs(a-c)*n; B=abs(b-d)*m; if(A==B){ cout<<"infinity"<<endl; return 0; } if(A>B){ cout<<0<<endl; return 0; } else { if(A%(B-A)==0){ cout<<(A/(B-A))*2<<endl; return 0; } cout<<(A/(B-A))*2+1<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; int main(){ ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll d1=(a1-b1)*t1, d2=(a2-b2)*t2; if(d1>0){ d1*=-1, d2*=-1; } if(d2<0) cout << 0 << endl; else if(d1+d2==0) cout << "infinity" << endl; else if(d1+d2<0) cout << 0 << endl; else{ ll ans=2*(ll)((-d1)/(d1+d2)); if((-d1)%(d1+d2)!=0) ans++; cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD=1e9+7; int main() { ll t1,t2,a1,a2,b1,b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; if(a1*t1+a2*t2==b1*t1+b2*t2) { cout<<"infinity"; return 0; } ll c1=(a1-b1)*t1,c2=(a2-b2)*t2; if(c1>=0&&c2>=0) { cout<<"0"; return 0; } if(c1<=0&&c2<=0) { cout<<"0"; return 0; } if(abs(c1)>abs(c2)) { cout<<"0"; return 0; } else cout<<(2LL*(c1/(-(c1+c2))))+1-(c1%(c1+c2)==0)<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll t1,t2,a1,b1,a2,b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll p=(a1-b1)*t1; ll q=(a2-b2)*t2; if(p>0) { p=-p; q=-q; } if(p+q<0) cout << 0 << endl; else if(p+q==0) cout << "infinity" << endl; else if(p%(p+q)==0) cout << -p/(p+q)*2 << endl; else cout << -p/(p+q)*2+1 << endl; }
#include<bits/stdc++.h> using namespace std; using Lint=long long; Lint solve(Lint X,Lint Y) { if(X+Y==0) return -1; if(X<0) X=-X,Y=-Y; if(X==0) return 1; else{ if(X+Y>0) return 0; else{ Lint res=X/abs(X+Y)*2; if(X%abs(X+Y)!=0) res++; return res; } } } int main() { Lint t[2],a[2],b[2]; cin>>t[0]>>t[1]>>a[0]>>a[1]>>b[0]>>b[1]; Lint X=(a[0]-b[0])*t[0]; Lint Y=(a[1]-b[1])*t[1]; Lint ans=solve(X,Y); if(ans==-1) cout<<"infinity"<<endl; else cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans=0,t1,t2,a,b,c,d; int main(){ scanf("%lld %lld %lld %lld %lld %lld",&t1,&t2,&a,&b,&c,&d); a-=c; b-=d; a*=t1; b*=t2; if(a+b==0) printf("infinity\n"); else if(a>0&&a+b>0) printf("0\n"); else if(a<0&&a+b<0) printf("0\n"); else{ b=fabs(b+a); a=fabs(a); ans=a/b*2; if(a%b!=0) ans++; printf("%lld\n",ans); } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int t1, t2; ll a1, a2, b1, b2; int main() { cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (a1 < b1) { swap(a1, b1); swap(a2, b2); } ll d = (b1 * t1 + b2 * t2) - (a1 * t1 + a2 * t2); if (d < 0) { cout << 0 << endl; return 0; } if (d == 0) { cout << "infinity" << endl; return 0; } ll d0 = a1 * t1 - b1 * t1; ll k = d0 / d; ll ans = 2 * k + 1; if (d * k == d0) ans--; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int t1,t2,a1,a2,b1,b2; signed main(){ cin>>t1>>t2>>a1>>a2>>b1>>b2; int t3=t1*a1,t4=t1*b1,t5=t2*a2,t6=t2*b2; if(t3>t4&&t5>t6){ printf("0"); return 0; } if(t3<t4&&t5<t6){ printf("0"); return 0; } if(t3<t4&&t3+t5<t4+t6){ printf("0"); return 0; } if(t3>t4&&t3+t5>t4+t6){ printf("0"); return 0; } if(t3>t4){ swap(t3,t4); swap(t5,t6); } //cout<<t3<<" "<<t5<<endl; int temp=t3+t5-t4-t6; if(!temp){ printf("infinity"); return 0; } int temp2=t4-t3; //cout<<temp<<" "<<temp2; int op=(temp2/temp)*2; if(temp2%temp==0)op--; cout<<op+1; return 0; }
#include<bits/stdc++.h> using namespace std; long long t1,t2,a1,a2,b1,b2; long long d1,d2; long long down,up; int main() { cin>>t1>>t2>>a1>>a2>>b1>>b2; d1=t1*(a1-b1); d2=t2*(a2-b2); if(d1==(-d2)) { cout<<"infinity"<<endl; return 0; } down=min(min(down,d1),d1+d2); up=max(max(up,d1),d1+d2); long long ans=0; if(d1+d2>0) { ans+=((-down)/(d1+d2)+1)*2; if(ans>0) --ans; if((-down)%(d1+d2)==0) --ans; } else { ans+=(up/(-d1-d2)+1)*2; if(ans>0) --ans; if(up%(-d1-d2)==0) --ans; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll t1,t2,a1,a2,b1,b2; ll x,y; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>t1>>t2>>a1>>a2>>b1>>b2; x=t1*(a1-b1); y=t2*(b2-a2); if(x<0){ x=-x;y=-y; } if(x>y){ cout<<0<<endl; return 0; } if(x==y){ cout<<"infinity"<<endl; return 0; } cerr<<x<<' '<<y<<endl; cout<<x/(y-x)*2+((bool)(x%(y-x)))<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long template<typename T> void fin(T a){ cout<<a<<endl; exit(0); } signed main(){ int t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2; a1-=b1;a2-=b2; if(a1>0)a1*=-1,a2*=-1; int A=t1*a1+t2*a2,B=-t1*a1; if(A<0)fin(0); if(!A)fin("infinity"); fin(B/A+(B-1)/A+1); }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); using ll = long long; ll T1,T2; cin>>T1>>T2; ll A1,A2; cin>>A1>>A2; ll B1,B2; cin>>B1>>B2; ll d1 = T1*(A1-B1); ll dd = d1 + T2*(A2-B2); if (dd == 0) { cout << "infinity" << endl; } else if (d1/abs(d1) == dd/abs(dd)) { cout << 0 << endl; } else { ll ans; if (abs(d1)%abs(dd) == 0) { ans = abs(d1)/abs(dd)*2; } else { ans = abs(d1)/abs(dd)*2+1; } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long t1,t2;cin>>t1>>t2; long long a1,a2;cin>>a1>>a2; long long b1,b2;cin>>b1>>b2; long long a1g=(a1-min(a1,b1))*t1; long long a2g=(a2-min(a2,b2))*t2; long long b1g=(b1-min(a1,b1))*t1; long long b2g=(b2-min(a2,b2))*t2; if(a1g==0&&a2g==0||b1g==0&&b2g==0)cout<<0<<endl; else { long long p1=a1g+b1g; long long p2=a2g+b2g; if(p1==p2)cout<<"infinity"<<endl; else if(p1>p2)cout<<0<<endl; else { long long p=p1/(p2-p1); long long ans=p*2+1; if(p1%(p2-p1)==0)ans--; cout<<ans<<endl; } } }
#include <bits/stdc++.h> using namespace std; long long t1,t2,a1,b1,a2,b2; int main() { cin>>t1>>t2>>a1>>b1>>a2>>b2; if (a1*t1+b1*t2==a2*t1+b2*t2) puts("infinity"); else { long long res=0; long long f1=t1*a1,f2=t2*b1; long long g1=t1*a2,g2=t2*b2; if (f1<g1) { swap(f1,g1); swap(f2,g2); } if (f1+f2<g1+g2) { res+=2*((f1-g1)/(g1+g2-f1-f2)); if ((f1-g1)%(g1+g2-f1-f2)) ++res; } cout<<res<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { vector<ll> t(2), a(2), b(2); cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1]; if(b[0] > a[0]) { swap(a[0], b[0]); swap(a[1], b[1]); } ll ad = t[0] * a[0] + t[1] * a[1]; ll bd = t[0] * b[0] + t[1] * b[1]; cerr << bd - ad << endl; if(bd - ad < 0) { cout << 0 << endl; } if(bd - ad == 0) { cout << "infinity" << endl; } if(bd - ad > 0) { ll sa = a[0] *t[0] - b[0] * t[0]; cout << (sa / (bd - ad))*2 + 1 - ((sa % (bd - ad)) == 0)<< endl; } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int t[2]; long long a[2], b[2], c,d; int main(){ scanf("%d%d%lld%lld%lld%lld", t,t+1,a,a+1,b,b+1); c = (a[0]-b[0]) * t[0]; d = c + (a[1]-b[1]) * t[1]; if(c > 0) d = -d; else c = -c; if(d == 0) puts("infinity"); else if(d < 0) printf("0\n"); else printf("%lld\n", c/d*2+(c%d!=0)); }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll T[2],A[2],B[2],N,D,ans; int main(void){ cin >> T[0] >> T[1] >> A[0] >> A[1] >> B[0] >> B[1]; if(A[0]<B[0]){ swap(A[0],B[0]); swap(A[1],B[1]); } D = (B[0]*T[0] +B[1]*T[1])-(A[0]*T[0] +A[1]*T[1]); //cout << D << endl; if(D==0){cout << "infinity" << endl;return 0;} if(D<0){cout << 0 << endl;return 0;} if(D>0){ N = (T[0]*A[0] - T[0]*B[0])/D; ans = N*2+1; if((T[0]*A[0] - T[0]*B[0])%D==0)ans--; cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; long long v1 = a1 - b1; long long v2 = a2 - b2; long long x1 = v1 * t1; long long x2 = v2 * t2; long long T = x1 + x2; if(T == 0) cout << "infinity" << endl; else if((x1>0 && T>0) || (x1<0 && T<0)) cout << 0 << endl; else{ if (x1 < 0) x1 *= -1; else T *= -1; long long n = x1 / T; if (x1 % T != 0){ cout << 2*n+1 << endl; } else{ cout << 2*n << endl; } } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll t1,t2,a1,a2,b1,b2; int main() { scanf("%lld%lld%lld%lld%lld%lld",&t1,&t2,&a1,&a2,&b1,&b2); ll a=a1-b1,b=a2-b2; if(a<0) a*=-1,b*=-1; ll k=t1*a+t2*b; if(k==0) {printf("infinity\n");return 0;} if(k>0){printf("0\n");return 0;} ll ans=a*t1/(-k)-b*t2/(-k); if(-b*t2%(-k)==0) ans--; printf("%lld\n",ans); }
#include<bits/stdc++.h> using namespace std; int main(){ long long t1,t2,a1,a2,b1,b2; cin>>t1>>t2; cin>>a1>>a2; cin>>b1>>b2; long long saa=t1*a1-t1*b1; long long sab=t2*a2-t2*b2; long long sac=saa+sab; long long num=abs(saa/sac); long long num2=abs(saa%sac); if(sac==0){ cout<<"infinity"<<endl; }else if(saa>0&&sac>0){ cout<<"0"<<endl; }else if(saa<0&&sac<0){ cout<<"0"<<endl; }else{ if(num2==0){ cout<<2*num<<endl; }else{ cout<<2*num+1<<endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll t1,t2; cin >> t1 >> t2; ll a1,b1,a2,b2; cin >> a1 >> a2 >> b1 >> b2; if( a1 < b1 ){ swap(a1,b1); swap(a2,b2);} ll d1 = (a1-b1)*t1; ll d2 = (a2-b2)*t2; if( d1+d2 > 0){ cout << 0 << endl;} else if( d1+d2 == 0 ){ cout <<"infinity" << endl;} else{ ll k = ceil( (long double)d2/(d1+d2) ); if( d1*k+d2*(k-1) < 0){ cout << 2*k-3 << endl;} else{ cout << 2*k-2 << endl;} } return 0; }
#include <iostream> using namespace std; typedef long long ll; int main() { ll t1,t2; ll a1,a2,b1,b2; cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; if(t1*a1 < t1*b1) { swap(a1,b1); swap(a2,b2); } ll tmp1 = t1*a1-t1*b1; ll tmp2 = t1*a1+t2*a2-(t1*b1+t2*b2); if(tmp2 == 0) { cout << "infinity" << endl; return 0; } else if (tmp2 > 0) { cout << 0 << endl; return 0; } if((tmp1 % (-tmp2)) == 0) { cout << (tmp1 / -tmp2) * 2 << endl; } else { cout << (tmp1 / -tmp2) * 2 + 1 << endl; } }
#include<bits/stdc++.h> #define puts(x) cout << x << "\n" using namespace std; long long t1, t2, a1, a2, b1, b2; int main() { cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; a1 = (a1 - b1) * t1; a2 = (a2 - b2) * t2; if (a1 + a2 == 0)puts("infinity"); else if (a1/abs(a1) * a2 > 0 || abs(a1) > abs(a2))puts(0); else { long long ans = (abs(a2) / abs(a1 + a2)) * 2 - 1; if (abs(a2) % abs(a1 + a2) == 0)ans--; puts(ans); } }
#include <bits/stdc++.h> #define int long long typedef long long ll; using namespace std; ll T1, T2, A1, A2, B1, B2, ans=0, tmp=0; signed main(){ cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if(A1*T1+A2*T2==B1*T1+B2*T2) { cout << "infinity" << endl; return 0; } if(A1>B1&&A2*T2+A1*T1>B2*T2+B1*T1||A1<B1&&A2*T2+A1*T1<B2*T2+B1*T1) { cout << 0 << endl; return 0; } ans = abs((A1-B1)*T1)/abs((A1-B1)*T1+(A2-B2)*T2); ans = 2*ans+1; //cout << ans << endl; if(abs((A1-B1)*T1)%abs((A1-B1)*T1+(A2-B2)*T2)==0) { ans--; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ ll T1,T2,A1,A2,B1,B2;cin>>T1>>T2>>A1>>A2>>B1>>B2; ll C=T1*A1-T1*B1,D=T2*A2-T2*B2,ans=0; if(C+D==0){ cout<<"infinity"<<endl; return 0; } if(C>0){ if(C+D<0){ ans=C/(-C-D)*2; if(C%(C+D))ans+=1; } } else{ if(C+D>0){ ans=-C/(C+D)*2; if(C%(C+D))ans+=1; } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; constexpr int mod=1e9+7; signed main(){ int t1,t2,a1,a2,b1,b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; a1*=t1,a2*=t2,b1*=t1,b2*=t2; a2+=a1,b2+=b1; if(a2==b2){ cout<<"infinity"<<endl; return 0; } if(a2<b2){ swap(a1,b1); swap(a2,b2); } if(a1>b1){ cout<<0<<endl; return 0; } cout<<(b1-a1)/(a2-b2)*2+!!((b1-a1)%(a2-b2))<<endl; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string> #include <cmath> using ll = long long; using namespace std; int main() { long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; long d1 = t1 * (a1 - b1), d2 = t2 * (a2 - b2); if (d1 == 0 || d1 + d2 == 0) { cout << "infinity\n"; return 0; } long ab1 = abs(d1), ab2 = abs(d1 + d2); if (d1 / ab1 == (d1 + d2) / ab2) { cout << 0 << '\n'; return 0; } cout << 2 * (ab1 / ab2) + (ab1 % ab2 > 0) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void){ ll t[2], a[2], b[2]; cin >> t[0] >> t[1]; cin >> a[0] >> a[1]; cin >> b[0] >> b[1]; ll am = t[0]*a[0]; ll bm = t[0]*b[0]; ll ah = t[0]*a[0] + t[1]*a[1]; ll bh = t[0]*b[0] + t[1]*b[1]; if (ah == bh) { cout << "infinity" << endl; return 0; } if ((am-bm > 0) ^ (ah-bh > 0)) { ll dm = abs(am-bm); ll dh = abs(ah-bh); ll res = (dm/dh)*2+1; if (dm % dh == 0) res--; cout << res << endl; } else { cout << 0 << endl; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAXN 200002 #define LL long long using namespace std; LL a,b,c,d,t1,t2; int main() { cin>>t1>>t2>>a>>b>>c>>d; LL A=(a-c)*t1; LL B=A+(b-d)*t2; if(B==0) { printf("infinity\n"); } else if((B>0&&A>0)||(B<0&&A<0)) { cout<<0<<endl; } else { cout<<-(A/B)*2+(A%B!=0)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { int64 T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if(A1 < B1) { swap(A1, B1); swap(A2, B2); } int64 S = T1 * A1 + T2 * A2; int64 T = T1 * B1 + T2 * B2; if(S == T) { cout << "infinity" << endl; } else { int64 U = B2 * T2 - A2 * T2; if(U % (T - S) == 0) cout << max(U / (T - S) * 2 - 2, 0LL) << endl; else cout << max(U / (T - S) * 2 - 1, 0LL) << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll t[2], a[2], b[2]; cin >> t[0] >> t[1]; cin >> a[0] >> a[1]; cin >> b[0] >> b[1]; ll p = (b[0]-a[0])*t[0]; ll q = (b[1]-a[1])*t[1]; if(p + q == 0){ cout << "infinity\n"; } else if (abs(q) < abs(p) || (q > 0 && p > 0) || (q < 0 && p < 0)){ cout << 0 << endl; } else { ll dx = abs(p + q); ll n = abs(p) / dx; if(abs(p) == n * dx){ cout << 2 * n << endl; } else { cout << 2 * n + 1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main () { long long T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; long long a1 = A1*T1, a2 = A2*T2, b1 = B1*T1, b2 = B2*T2; if (a1+a2 == b1+b2) { puts("infinity"); return 0; } if (a1 < b1) { swap(a1, b1); swap(a2, b2); } // a1 > b1 if (a1+a2 > b1+b2) { puts("0"); return 0; } // a1+a2 < b1+b2 long long c = (b1+b2)-(a1+a2); long long ans = 1; ans += ((a1-b1) / c) * 2; if ((a1-b1) % c == 0) { ans--; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { ll t1, t2; ll a1, a2; ll b1, b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; a1 *= t1; a2 *= t2; b1 *= t1; b2 *= t2; a2 += a1; b2 += b1; if (a2 == b2) { puts("infinity"); return 0; } if (a2 < b2) { swap(a1,b1); swap(a2,b2); } ll d = a2-b2; ll c = b1-a1; ll ans = 0; if (c > 0) { ans = (c-1)/d+1; ans *= 2; ans--; if (c%d == 0) ans++; } cout << ans << endl; return 0; }
#include <iostream> #include <utility> using namespace std; int main() { long long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; // make a1 > b1 if (a1 < b1) { swap(a1, b1); swap(a2, b2); } auto d1 = (a1 - b1) * t1; // d1 > 0 auto d2 = (a2 - b2) * t2; if (d1 + d2 == 0) { cout << "infinity"; return 0; } if (d1 + d2 > 0) { cout << 0; return 0; } if (-d1 % (d1 + d2) == 0) { auto n = -d1 / (d1 + d2); cout << (2 * n); return 0; } auto n = -d1 / (d1 + d2); cout << (2 * n + 1); return 0; }
#include <stdio.h> long long t[2], a[2], b[2]; long long w, x, y, z, e, f; long long ans; int main() { scanf("%lld%lld", t, t + 1); scanf("%lld%lld", a, a + 1); scanf("%lld%lld", b, b + 1); x = t[0]; y = t[1]; w = b[0] - a[0]; z = b[1] - a[1]; e = w * x + z * y; if (e == 0) { printf("infinity\n"); return 0; } if (e > 0) { w = -w; z = -z; e = -e; } if (w < 0) { printf("0\n"); return 0; } f = w * x; e = -e; ans = f / e * 2; if (f % e)ans++; printf("%lld\n", ans); }
#include <iostream> #include <vector> #include <string> #include <algorithm> #define MOD 1000000007 #define INF 1 << 30 using namespace std; typedef long long ll; int Sign(ll a) { return (a > 0) - (a < 0); } int main(void) { int num, i, j; ll ans = 1; ll d1, d2, a1, a2, b1, b2, t1, t2; cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; d1 = (a1 - b1) * t1; d2 = (a2 - b2) * t2 + d1; if (Sign(d1) * Sign(d2) >= 0) { if (Sign(d1) * Sign(d2) == 0) printf("infinity\n"); else printf("0\n"); } else { ans += abs(d1) / abs(d2) * 2; if (abs(d1) % abs(d2) == 0) ans--; cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long int t1, t2; long long int a1, a2, b1, b2; cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; long long int d1 = (a1 - b1)*t1; long long int d2 = (a2 - b2)*t2; if(d1>0) { d1 = -1*d1; d2 = -1*d2; } if(d1+d2<0) { cout << 0 << '\n'; return 0; } else if(d1+d2==0) { cout << "infinity" << '\n'; return 0; } long long int res = -d1/(d1+d2); if((-d1)%(d1+d2)==0) { cout << 2*res << '\n'; } else { cout << 2*res+1 << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { vector<ll> t(2), a(2), b(2); cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1]; ll as = t[0] * a[0] + t[1] * a[1], bs = t[0] * b[0] + t[1] * b[1]; if (as == bs) { cout << "infinity" << endl; return 0; } else if (as < bs) { swap(a[0], b[0]); swap(a[1], b[1]); } vector<ll> d{t[0] * a[0] - t[0] * b[0], t[1] * a[1] - t[1] * b[1]}; d[1] += d[0]; if (d[0] > 0) { cout << 0 << endl; return 0; } cout << ((-d[0]) % d[1] == 0 ? (-d[0]) / d[1] * 2 : (-d[0]) / d[1] * 2 + 1) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ll t1,t2,a1,a2,b1,b2; scanf("%lld %lld",&t1,&t2); scanf("%lld %lld",&a1,&a2); scanf("%lld %lld",&b1,&b2); ll a=a1-b1,b=a2-b2; if(a<0) { a=-a,b=-b; } ll sum=a*t1+b*t2; if(sum==0) { puts("infinity"); return 0; } if(sum>0) { puts("0"); return 0; } ll ret=a*t1/(-sum)+(-b)*t2/(-sum); if((-b)*t2%(-sum)==0) ret--; printf("%lld\n",ret); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN=2e5+10,MAXM=2e6+10; const int INF=INT_MAX,MOD=1e9+7; const ll llINF=~(1ll<<63); int main() { ll t1,t2,a1,a2,b1,b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; ll ans=(a1-b1)*t1+(a2-b2)*t2; if(!ans)return puts("infinity"),0; ll x1=t1*a1-t1*b1; if(!x1)return puts("infinity"),0; if((x1>0)==(ans<0)) { ll p=x1+ans,res=0; if(abs(x1)%abs(ans))res++; printf("%lld",abs(x1/ans)*2+res); } else return puts("0"),0; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; ll t1, t2; ll a1, a2; ll b1, b2; void solve() { ll s, t; s = a1*t1 - b1*t1; t = s + a2*t2 - b2*t2; if (t == 0) cout << "infinity" << endl; else if ((s>0 && t>0) || (s<0 && t<0)) cout << 0 << endl; else { ll u = (s > 0 ? s / (-t) : (-s) / t); ll v = (s > 0 ? s % (-t) : (-s) % t); cout << u*2LL + (v ? 1LL : 0LL) << endl; } } int main() { cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; solve(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=int(a);i<int(b);++i) using namespace std; typedef long long ll; int INF = (1LL << 30) - 1; int MOD = 1e9+7; int main(){ ll T1,T2,A1,A2,B1,B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; ll p = (A1 - B1) * T1; ll q = (A2 - B2) * T2; if(p > 0){ p *= -1; q *= -1; } if(p + q < 0){ cout << 0 << endl; }else if(p + q == 0){ cout << "infinity" << endl; }else{ ll s = (-p) / (p + q); ll t = (-p) % (p + q); cout << (s * 2 + (t == 0 ? 0 : 1)) << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) using ll=long long; const ll X=1000000007; int main() { ll T1,T2,A1,A2,B1,B2,TA,TB,AA,AB,D; cin>>T1>>T2>>A1>>A2>>B1>>B2; TA=T1*A1; TB=T2*A2; AA=T1*B1; AB=T2*B2;//高橋青木の前後半で進む距離 D=TA+TB-AA-AB; if(TA+TB==AA+AB){ cout<<"infinity"<<endl; } else{ if(D<0){swap(TA,AA);swap(TB,AB);D=-D;} //以降は高橋の方が先に進む場合のみ if(TA>AA){cout<<0<<endl;} else{ ll d=AA-TA; if(d%D==0){ cout<<2*(d/D)<<endl; } else{ cout<<2*(d/D)+1<<endl; } } } }
#include <bits/stdc++.h> #define ll long long #define loop(a) loopi(i,a) #define loopi(i,a) for(int i=0; i<a; i++) #define pii pair<int,int> #define pll pair<ll,ll> using namespace std; const int mod=1e9+7; int main(){ ios_base::sync_with_stdio(0),cin.tie(0); ll t1,t2,a1,a2,b1,b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll diff=a1*t1+a2*t2-b1*t1-b2*t2; if(diff==0){ cout << "infinity\n"; return 0; } if(diff<0){ swap(a1,b1); swap(a2,b2); diff*=-1; } if(a1>b1){ cout << "0\n"; return 0; } ll x=b1*t1-a1*t1; ll ans=1+2*((x-1)/diff); if(x%diff==0) ans++; cout << ans << "\n"; return 0; }
#include <iostream> #include <string> #define llint long long #define mod 1000000007 using namespace std; llint t1, t2; llint a1, a2, b1, b2; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if(a1 < b1) swap(a1, b1), swap(a2, b2); llint d1 = a1-b1, d2 = a2-b2; llint dif = d1*t1+d2*t2; if(dif == 0){ cout << "infinity" << endl; return 0; } if(dif > 0){ cout << 0 << endl; return 0; } dif *= -1; llint top = d1*t1; llint ans = (top+dif-1)/dif*2; if(top % dif == 0) ans++; cout << ans-1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, N) for (int i = 0; i < (int)N; i++) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const int INF = pow(2,30)-1; int main() { ll T1, T2; cin >> T1 >> T2; ll A1, A2; cin >> A1 >> A2; ll B1, B2; cin >> B1 >> B2; if (A1*T1+A2*T2==B1*T1+B2*T2) { cout << "infinity" << endl; return 0; } if (A1<B1) { swap(A1,B1); swap(A2,B2); } ll d1 = A1*T1 - B1*T1; ll d2 = (B1*T1+B2*T2) - (A1*T1+A2*T2); if (d2<0) cout << 0 << endl; else cout << d1/d2*2+(d1%d2!=0) << endl; // cout << d1 << " " << d2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int T1, T2, A1, A2, B1, B2; cin >> T1 >> T2; cin >> A1 >> A2; cin >> B1 >> B2; A1 *= T1; A2 *= T2; B1 *= T1; B2 *= T2; if(A1+A2 == B1+B2) {puts("infinity"); return 0;} if(A1+A2 < B1+B2) { swap(A1, B1); swap(A2, B2); } if(A1 > B1) {puts("0"); return 0;} // A1 < B1 int D1=A1-B1; int D2=A2-B2; assert(D1<0); assert(D2>0); int S = abs(D1)/(D1+D2); int T = abs(D1)%(D1+D2); if(T==0) cout << 2*S << endl; else cout << 2*S + 1 << endl; }
#include <iostream> using namespace std; int main() { long long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2) { swap(a1, b1); swap(a2, b2); } if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) { cout << "infinity"; } else if (a1 < b1) { cout << 0; } else { long long top = t1 * (a1 - b1), bot = t1 * (b1 - a1) + t2 * (b2 - a2); long long result = 2 * (top / bot); if (top % bot != 0) { result++; } cout << result; } return 0; }
#include<iostream> using namespace std; long T1,T2,A1,A2,B1,B2; int main() { cin>>T1>>T2>>A1>>A2>>B1>>B2; long X=A1*T1+A2*T2,Y=B1*T1+B2*T2; if(X==Y) { cout<<"infinity"<<endl; } else { long d,D; if(X>Y) { d=B1*T1-A1*T1; D=X-Y; } else { d=A1*T1-B1*T1; D=Y-X; } if(d<0)cout<<0<<endl; else if(d==0)cout<<1<<endl; else { long ans=1; d-=D; if(d>=0) { ans+=d/D*2; d%=D; ans+=2; if(d==0)ans--; } cout<<ans<<endl; } } }
#include <iostream> using namespace std; int main(void){ long long T1,T2,A1,A2,B1,B2,a,c,ans; cin>>T1>>T2>>A1>>A2>>B1>>B2; if((A1-B1)*T1+(A2-B2)*T2==0){ cout<<"infinity"<<endl; return 0; } if((A1-B1)*T1+(A2-B2)*T2<0){ c=A1;A1=B1;B1=c; c=A2;A2=B2;B2=c; } if(A1>B1){ cout<<0<<endl; return 0; } a=(A1-B1)*T1+(A2-B2)*T2; if((B1*T1-A1*T1)%a==0){ ans=((B1*T1-A1*T1-1)/a+1)*2; }else{ ans=((B1*T1-A1*T1)/a+1)*2-1; } if(ans<0){ ans=0; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> nums[100005]; int main(){ ll t1,t2,a1,a2,b1,b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; if(a1<b1){ swap(a1,b1); swap(a2,b2); } ll t=t1*(a1-b1),d=t+t2*(a2-b2); if(d>0) cout<<0<<endl; else if(d==0) cout<<"infinity"<<endl; else{ t*=-1; ll ans=t/d; ans*=2; if((ans/2)*d==t) ans--; cout<<ans+1<<endl; } }
#include<bits/stdc++.h> using namespace std; long long t1,t2,a1,a2,b1,b2,a,b,s,ret; int main(){ //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>t1>>t2; cin>>a1>>a2; cin>>b1>>b2; a=a1-b1; b=a2-b2; if(a<0){ a=-a; b=-b; } s=a*t1+b*t2; if(s==0){ cout<<"infinity"<<endl; return 0; } if(s>0){ cout<<"0"<<endl; return 0; } if(s<0){ ret=a*t1/(-s)+(-b)*t2/(-s); if((-b)*t2%(-s)==0LL) ret-=1LL; cout<<ret<<endl; return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; long long T1, T2, A1, A2, B1, B2; int main() { cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; long long SA = A1*T1 + A2*T2; long long SB = B1*T1 + B2*T2; if(SA == SB) cout << "infinity"; else if((SA > SB && A1 > B1) || (SA < SB && A1 < B1)) cout << 0; else { long long ds = abs(SA - SB); long long rd = abs(A1 - B1) * T1; long long ans = (rd / ds) * 2; if(rd % ds) ans++; cout << ans; } }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)n; i++) using namespace std; using ll = long long; int main(){ ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll diff1 = (a1 - b1) * t1; ll diff2 = (a2 - b2) * t2; if(0 < diff1) { diff1 = -diff1; diff2 = -diff2; } if(diff1 + diff2 < 0) { cout << 0 << endl; return 0; } else if(diff1 + diff2 == 0) { cout << "infinity" << endl; return 0; } ll answer = (-diff1/(diff1+diff2)) * 2 + (-diff1%(diff1+diff2) != 0); cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; long p = t1 * (b1 - a1), q = t2 * (b2 - a2); if(p > 0 && q > 0 || p < 0 && q < 0 || abs(p) > abs(q)) { cout << 0 << endl; return 0; } p = abs(p), q = abs(q); if(p == q) { cout << "infinity" << endl; return 0; } cout << p / (q - p) * 2 + !!(p % (q - p)) << endl; return 0; }
#include<iostream> #include<cstdint> int64_t T1, T2, V1, V2; int main() { int64_t A1, A2, B1, B2; std::cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; V1 = A1-B1; V2 = A2-B2; if(V1 < 0) { V1 = -V1; V2 = -V2; } int64_t dm = V1*T1, d = dm + V2*T2; if(d > 0) { std::cout << "0" << std::endl; return 0; } if(d == 0) { std::cout << "infinity" << std::endl; return 0; } int64_t ans = 1; int64_t r = (dm-1)/(-d); ans += r*2; if(dm%(-d)==0) ++ans; std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int T1, T2; ll A1, A2; ll B1, B2; int main() { cin >> T1 >> T2; cin >> A1 >> A2; A1 *= T1; A2 *= T2; cin >> B1 >> B2; B1 *= T1; B2 *= T2; if (A1 + A2 == B1 + B2) { printf("infinity\n"); return 0; } if (A1 + A2 > B1 + B2) { swap(A1, B1); swap(A2, B2); } if (A1 > B1) { ll r = (A1 - B1) / (B1 + B2 - A1 - A2); ll res = 2ll * r; if ((A1 - B1) % (B1 + B2 - A1 - A2)) res++; cout << res << endl; } else printf("0\n"); return 0; }
#include <bits/stdc++.h> typedef long long int LL; typedef unsigned long long int ULL; using namespace std; // 插入此處 int main() { std::ios::sync_with_stdio(false); cin.tie(0); LL T1, T2; cin >> T1 >> T2; LL A1, A2, B1, B2; cin >> A1 >> A2 >> B1 >> B2; if (A1 - B1 < 0) { swap(A1, B1); swap(A2, B2); } LL s1 = (A1-B1)*T1; LL s2 = (A2-B2)*T2; if ((A1-B1)*T1 + (A2-B2)*T2 > 0) cout << "0" << endl; else if ((A1-B1)*T1 + (A2-B2)*T2 == 0) cout << "infinity" << endl; else cout << s1/(-(s1+s2)) * 2 - 1 + (s1%(-(s1+s2)) == 0 ? 1 : 2) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { long long T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if (T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) { cout << "infinity" << endl; return 0; } if (A1 < B1) swap(A1, B1), swap(A2, B2); if (T1 * A1 + T2 * A2 > T1 * B1 + T2 * B2) { cout << 0 << endl; return 0; } long long SA1 = T1 * A1, SA2 = T2 * A2, SB1 = T1 * B1, SB2 = T2 * B2; long long ANS = (SA1 - SB1 - 1) / (SB1 + SB2 - SA1 - SA2) * 2 + 1; long long ANS2 = (ANS + 1) / 2; if (ANS2 * (SB1 + SB2 - SA1 - SA2) == SA1 - SB1) cout << ANS2 * 2 << endl; else cout << ANS << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); LL T1,T2,A1,A2,B1,B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; LL D1 = A1-B1, D2 = A2-B2; if(D1 > 0){ D1 = -D1; D2 = -D2; } LL X = T1*D1, Y = T2*D2; if(D2 < 0){ cout << 0 << endl; }else if(-X == Y){ cout <<"infinity" << endl; }else if(X+Y < 0){ cout << 0 << endl; }else{ LL res = (-X)/(X+Y)*2 + (((-X)%(X+Y)==0)?0:1); cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int T1, T2; long long A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; long long a=T1*A1-T1*B1, b=T2*A2-T2*B2; if(a==-b){ cout << "infinity"<< endl; return 0; } long long ans=0; if((a<0 && a+b>0) || (a>0 && a+b<0)){ ans=abs(a/(a+b))*2; if(a%(a+b)!=0) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int T1, T2; long long A1, A2, B1, B2, P, Q; int main() { cin >> T1 >> T2; cin >> A1 >> A2; cin >> B1 >> B2; P = (A1 - B1) * T1; Q = (A2 - B2) * T2; if(P > 0){ P *= -1; Q *= -1; } if( P + Q < 0){ cout << 0 << endl; } else if(P + Q == 0) { cout << "infinity" << endl; } else { long long int S = (-P) / (P+Q); long long int T = (-P) % (P+Q); if (T!=0) cout << S * 2+1 << endl; else cout << S * 2 << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { long long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (a1 > b1) { swap(a1, b1); swap(a2, b2); } if (a1 == b1 || t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) { cout << "infinity" << endl; } else if (t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2) { cout << "0" << endl; } else { long long d1 = t1 * b1 - t1 * a1; long long d2 = (t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2); cout << 2 * (d1 / d2) - (d1 % d2 == 0 ? 1 : 0) + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long s, t; cin >> s >> t; long long a, b, c, d; cin >> a >> b >> c >> d; a *= s; c *= s; b *= t; d *= t; b += a; d += c; if (b == d) { cout << "infinity" << endl; return 0; } if ((b > d) == (a > c)) { cout << 0 << endl; return 0; } if (b > d) { swap(b, d); swap(a, c); } long long x = d - b; long long y = a - c; cout << (y / x) * 2 + 1 - (y % x == 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long t[2], a[2], b[2]; void solve(); int main() { cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1]; solve(); return 0; } void solve() { long long x = (a[0] - b[0]) * t[0], y = (b[1] - a[1]) * t[1]; if(x == y) { cout << "infinity" << endl; return; } if((x < 0 && y > 0) || (x > 0 && y < 0) || abs(x) - abs(y) > 0) { cout << 0 << endl; return; } if(x < 0) { x *= -1; y *= -1; } y -= x; cout << (x % y != 0) + 2 * (x / y) << endl; }
#include <iostream> #include <vector> using namespace std; int main() { long long A1, A2, B1, B2, T1, T2, D1, D2, D3, p, q; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; D1 = (A1 - B1) * T1; D2 = (A2 - B2) * T2; if (D1 < 0) { D1 *= -1; D2 *= -1; } if (D1 + D2 > 0) { cout << 0; } else if (D1 + D2 == 0) { cout << "infinity"; } else { // D1 + D2 < 0 // abs(D1) < abs(D2) D3 = -(D1 + D2); p = D1 / D3, q = D1 % D3; if (q) cout << p * 2 + 1; else cout << p * 2; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll t1,t2,a1,a2,b1,b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; a1 *= t1; a2 *= t2; b1 *= t1; b2 *= t2; if((a1 + a2) < (b1 + b2)){ swap(a1,b1); swap(a2,b2); } ll c1,c2; c1 = a1 - b1; c2 = a2 - b2; if(c1 + c2 == 0){ cout << "infinity" << endl; } else if(c1 > 0){ cout << 0 << endl; } else{ ll sum = 0; if(c1 < 0) sum--; sum += c2 / (c1 + c2) * 2; if(c2 % (c1 + c2) == 0) sum--; cout << sum << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { int64 T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; int64 S = T1 * A1 + T2 * A2; int64 T = T1 * B1 + T2 * B2; if(S == T) { cout << "infinity" << endl; } else { int64 U = B2 * T2 - A2 * T2; cout << max(U / (T - S) * 2 - 1 - (U % (T - S) == 0), 0LL) << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main(){ int t1,t2; cin >> t1 >> t2; ll a1,a2; cin >> a1 >> a2; ll b1,b2; cin >> b1 >> b2; ll dist1 = a1*t1 - b1*t1; ll dist2 = a2*t2 - b2*t2; if(dist1 > 0){ dist1 *= -1; dist2 *= -1; } if(dist1 + dist2 == 0){ cout << "infinity" << endl; return 0; } if(dist1 + dist2 < 0){ cout << 0 << endl; return 0; } ll s = (-dist1)/(dist1 + dist2); ll t = (-dist1)%(dist1 + dist2); if(t == 0){ cout << 2*s << endl; } else{ cout << 2*s+1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) { cout << "infinity" << endl; } else if ((t1 * a1 > t1 * b1) == (t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2)) { cout << 0 << endl; } else { cout << 1 + 2 * (abs(t1 * a1 - t1 * b1) / abs((t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2))) - (abs(t1 * a1 - t1 * b1) % abs((t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2)) == 0); } }
#include<bits/stdc++.h> #define INF 9223372036854775807LL #define inf 1000000007 #define lol long long #define abs(x,y) (max(x,y)-min(x,y)) #define mp make_pair #define fi first #define se second using namespace std; lol a,b,c; lol x,y; signed main(){ cin.tie(0); ios::sync_with_stdio(false); lol d=0,e=0,f=0; lol ans=0; string s; cin >>x>>y; cin >>a>>b>>c>>d; e=(a-c)*x,f=(b-d)*y; if(e==-f){ cout <<"infinity\n"; return 0; } if(e<0) e=-e,f=-f; if(e+f>0){ cout <<0<<'\n'; return 0; } c=-e/(e+f); if(-e%(e+f)==0) cout <<c*2<<'\n'; else cout <<c*2+1<<'\n'; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; long long x = t1 * (a1 - b1); long long y = t2 * (a2 - b2); if (x + y == 0) { cout << "infinity\n"; return 0; } if ((__int128) x * (x + y) >= 0) { cout << 0 << '\n'; return 0; } __int128 p = abs(x); __int128 q = abs(x + y); cout << (long long) (p / q * 2) + (p % q != 0) << '\n'; return 0; }
#include"bits/stdc++.h" using namespace std; #define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++) #define rep(i,n) REP((i),0,(n)) using ll=long long; ll T1,T2,A1,A2,B1,B2; int main() { cin>>T1>>T2>>A1>>A2>>B1>>B2; ll diff = abs((A1-B1)*T1+(A2-B2)*T2); ll gain = abs(A1-B1)*T1; if(diff==0){ cout<<"infinity"<<endl; return 0; } if((A1*T1>B1*T1)==(A1*T1+A2*T2>B1*T1+B2*T2)){ cout<<0<<endl; return 0; } cout<<2*(gain/diff+1)-1 - (gain%diff==0?1:0)<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long T1,T2,a,b,c,d,e,f; cin>>T1>>T2>>a>>c>>b>>d; if(a*T1+c*T2==b*T1+d*T2){ cout<<"infinity"; return 0; } if(a<b)swap(a,b),swap(c,d); e=a-b;f=c-d; if(e*T1+f*T2>0&&e*T1>0){ cout<<0; return 0; } if(e*T1+f*T2<0&&e*T1<0){ cout<<0; return 0; } cout<<2ll*(((a-b)*T1)/(-e*T1-f*T2))+bool(((a-b)*T1)%(1ll*(-e*T1-f*T2))); }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef long long ll; int main(){ ll t1,t2,a1,a2,b1,b2; cin>>t1>>t2>>a1>>a2>>b1>>b2; ll X01=(a1-b1)*t1,X02=X01+(a2-b2)*t2; if(X02==0){cout<<"infinity";return 0;} if(X01<0&&X02<0){cout<<0;return 0;} if(X01>0&&X02>0){cout<<0;return 0;} cout<<1-(abs(X01)%abs(X02)==0)+abs(X01)/abs(X02)*2; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int,int> P; int main() { ll t1,t2,a1,a2,b1,b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (a1*t1 + a2*t2 == b1*t1 + b2*t2) { cout << "infinity" << endl; return 0; } if (a1 < b1) { swap(a1,b1); swap(a2,b2); } if (a1*t1 + a2*t2 > b1*t1 + b2*t2) { cout << "0" << endl; } else { ll diff = (b1*t1 + b2*t2) - (a1*t1 + a2*t2); ll ans = 1 + (a1*t1 - b1*t1) / diff * 2; if ((a1*t1 - b1*t1) % diff == 0) ans--; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if(T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) puts("infinity"); else { if(T1 * A1 + T2 * A2 > T1 * B1 + T2 * B2) { swap(A1, B1); swap(A2, B2); } if(A1 < B1) puts("0"); else { cout << (A1 - B1) * T1 / ((T1 * B1 + T2 * B2) - (T1 * A1 + T2 * A2)) * 2 + 1 - ((A1 - B1) * T1 % ((T1 * B1 + T2 * B2) - (T1 * A1 + T2 * A2)) == 0)<< endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int t[2]; long long a[2], b[2], x, y; int main() { cin >> t[0] >> t[1] >> a[0] >> a[1] >> b[0] >> b[1]; x = (a[0] - b[0]) * t[0]; y = (a[1] - b[1]) * t[1]; if (x + y == 0) cout << "infinity" << endl; else if ((x > 0) ^ (x + y > 0)) cout << -x / (x + y) + (abs(y) - 1) / abs(x + y) << endl; else cout << 0 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll t1,t2,a1,a2,b1,b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; a1 *= t1; a2 *= t2; b1 *= t1; b2 *= t2; a2 += a1; b2 += b1; if(a2 == b2) { cout << "infinity" << '\n'; return 0; } if(a2 < b2) { swap(a1, b1); swap(a2, b2); } if(a1 > b1) { cout << 0 << '\n'; return 0; } ll c = b1-a1; ll d = a2-b2; // how many turns c can catch up d cout << c/d*2 + (c%d>0) << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; long long t1,t2,a1,a2,b1,b2,a,b,s,ret; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>t1>>t2; cin>>a1>>a2; cin>>b1>>b2; a=a1-b1; b=a2-b2; if(a<0){ a=-a; b=-b; } s=a*t1+b*t2; if(s==0){ cout<<"infinity"<<endl; return 0; } if(s>0){ cout<<"0"<<endl; return 0; } if(s<0){ ret=a*t1/(-s)+(-b)*t2/(-s); if((-b)*t2%(-s)==0LL) ret-=1LL; cout<<ret<<endl; return 0; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll t1,t2,a1,a2,b1,b2; int main() { scanf("%lld%lld%lld%lld%lld%lld",&t1,&t2,&a1,&a2,&b1,&b2); ll a=a1-b1,b=a2-b2; if(a<0) a*=-1,b*=-1; ll k=t1*a+t2*b; if(k==0) {printf("infinity\n");return 0;} if(k>0){printf("0\n");return 0;} ll ans=a*t1/(-k)*2+(b*t2%k!=0); printf("%lld\n",ans); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long int ll; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll a = t1 * a1 - t1 * b1; ll b = t2 * a2 - t2 * b2; if (a > 0) { a *= -1; b *= -1; } if (a + b < 0) cout << 0 << endl; else if (a + b == 0) cout << "infinity" << endl; else { ll s = -a / (a + b); ll t = -a % (a + b); if (t == 0) cout << s * 2 << endl; else cout << s * 2 + 1 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; const ll mod = 1e9+7; int main(void){ ll t1,t2; ll a1,a2; ll b1,b2; cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; if(b1 > a1){ swap(a1,b1); swap(a2,b2); } ll A = (a1 - b1) * t1; ll B = (b2 - a2) * t2; if(A == B){ puts("infinity"); return 0; } if(A > B){ puts("0"); return 0; } ll cnt = A / (B-A); if(A % (B-A) == 0){ cout << 2 * cnt << endl; } else { cout << 2 * cnt + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long int n,t1,t2,a1,a2,b1,b2,sa1,sa2,kotae; cin>>t1>>t2>>a1>>a2>>b1>>b2; sa1=a1*t1-b1*t1; sa2=a2*t2-b2*t2+sa1; if(sa1>0&&sa2>0){ cout<<0; return 0; } if(sa1<0&&sa2<0){ cout<<0; return 0; } if(sa2==0){ cout<<"infinity"; return 0; } sa1=abs(sa1); sa2=abs(sa2); kotae=sa1/sa2*2+1; if(sa1%sa2==0){ kotae--; } cout<<kotae; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; ll step = T1*A1+T2*A2 - (T1*B1+T2*B2); ll hop = T1 * (A1 - B1); // != 0 if(step == 0) { cout << "infinity" << "\n"; return 0; } if((step > 0) == (hop > 0)){ cout << 0 << "\n"; return 0; } if(step < 0) step *= -1; if(hop < 0) hop *= -1; ll ans = hop / step; ans = ans * 2 + 1; if(hop % step == 0) ans--; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a) for(int i=0;i<(a);i++) const ll MOD=1000000007; //const ll MOD=998244353; int main(){ ll T[2],A[2],B[2]; cin>>T[0]>>T[1]; cin>>A[0]>>A[1]; cin>>B[0]>>B[1]; ll X=T[0]*A[0]+T[1]*A[1]; ll Y=T[0]*B[0]+T[1]*B[1]; if(X==Y){ cout<<"infinity\n"; return 0; } if(X>Y&&A[0]>B[0]){ cout<<0<<endl; return 0; } if(X<Y&&A[0]<B[0]){ cout<<0<<endl; return 0; } ll D=abs(X-Y); ll Z=abs(A[0]-B[0])*T[0]; cout<<Z/D*2+(Z%D!=0)<<endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ int A,B,C,D,E,F; cin>>A>>B>>C>>D>>E>>F; C-=E,D-=F; E=A*C,F=B*D; if(E<0)E*=-1,F*=-1; if(E+F>0)puts("0"); else if(E+F==0)puts("infinity"); else if(E%(-E-F))cout<<E/(-E-F)*2+1<<endl; else cout<<E/(-E-F)*2<<endl; }