bool findIntersectionEndpoints(int a0, int a1, int s, int b0, int b1, int t,
                               int &left, int &right, int &stride)
{
  // We should have both domains moving in positive directions, although
  // we might have to reverse the sign on the strides.
  PAssert(a0 <= a1 && b0 <= b1);
  if (s < 0)  s = -s;
  if (t < 0)  t = -t;

  // find the left endpoint first.  If we cannot, we're done.
  if (!findLeftCommonEndpoint(a0, a1, s, b0, b1, t, left))
    return false;

  // find the least-common-multiple of the strides s and t.  This will
  // be the stride of the resulting domain, if there is one possible.  But
  // first make sure the strides are positive, since we're assuming in this
  // routine that it was called with a0 <= a1, b0 <= b1.
  stride = findLCM(s, t);

  // find the minimum of the right endpoints, and then how far we must
  // move in from this endpoint to get a point in both domains.
  int m = a1;
  if (b1 < a1)
    m = b1;
  right = m - ((m - left) % stride);

  // we were able to find an intersection
  return true;
}
Exemplo n.º 2
0
int main(){
	long n;
	int ans[10] = {0, 1, 2, 6, 12, 60};
	
	sieve();
	while ( scanf("%ld", &n) != EOF ){
		if ( n < 6 ) printf("%d\n", ans[n]);
		else printf("%I64d\n", findLCM(n));
	}
	
	return 0;
}