October Challenge 2013

Codechef oct 2013 – Helping Lira

// Helping Lira - triangle area - easy

double area(int x1, int x2, int x3, int y1, int y2, int y3) {
	double r = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
	if(r < 0.0) r = -r;
	return r/2.0;
}

int main() {
	int N, x1, x2, x3, y1, y2, y3, minIt = 1, maxIt = 1;
	double mini, maxi, a;
	scanf("%d", &N);
	scanf("%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3);
	mini = maxi = area(x1, x2, x3, y1, y2, y3);
	for(int i=1; i<N ;i++) {
		scanf("%d %d %d %d %d %d", &x1, &y1, &x2, &y2, &x3, &y3);
		a = area(x1, x2, x3, y1, y2, y3);
		if(mini >= a) {
			mini = a;
			minIt = i+1;
		}
		if(maxi <= a) {
			maxi = a;
			maxIt = i+1;
		}
	}
	printf("%d %dn", minIt, maxIt);
}

Codechef oct 2013 – Maxim and Dividers

Verify divisor by divisor if it’s a lucky number. You only need to review up to sqrt(n).

// Maxim and Dividers - divisor - easy

bool isLucky(int x) {
	do{
		int a = x%10;
		if(a == 4 || a == 7)
			return true;
		x /= 10;
	} while(x);
	return false;
}

int main() {
	int T, n, res, x;
	scanf("%d", &T);
	for(int cas=0; cas<T ;cas++) {
		scanf("%d", &n);
		x = sqrt(n);
		res = isLucky(n);
		for(int i=2; i<=x ;i++) {
			if(n % i == 0) {
				if(isLucky(i))
					res++;
				if(n/i != i)
					if(isLucky(n/i))
						res++;
			}
		}
		printf("%dn", res);
	}
}