Submission #471556

# Submission time Handle Problem Language Result Execution time Memory
471556 2021-09-09T18:43:54 Z rainboy Sažetak (COCI17_sazetak) C
64 / 160
500 ms 264 KB
#include <stdio.h>

#define N	10
#define INF	0x3f3f3f3f

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int lcm(int a, int b) {
	long long c = a / gcd(a, b) * b;

	return c > INF ? INF : c;
}

int solve(int n, int a, int b) {
	int x, ans;

	ans = 0;
	for (x = b; x < n; x += b)
		if (x % a == 1)
			ans++;
	return ans;
}

int main() {
	static int kk[1 << N], aa[1 << N];
	int n, a, i, b, b1, b2;
	long long ans;

	scanf("%d%d", &a, &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[1 << i]);
	ans = 0;
	aa[0] = 1;
	for (b = 1; b < 1 << n; b++) {
		aa[b] = lcm(aa[b & -b], aa[b & b - 1]);
		kk[b] = kk[b & b - 1] + 1;
	}
	ans = 0;
	for (b1 = 1; b1 < 1 << n; b1++)
		for (b2 = 1; b2 < 1 << n; b2++)
			if ((b1 & b2) == 0)
				ans += solve(a - 1, aa[b1], aa[b2]) * ((kk[b1] + kk[b2]) % 2 == 0 ? 1 : -1);
	for (i = 0; i < n; i++)
		if ((a - 1) % aa[1 << i] == 0) {
			ans++;
			break;
		}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

sazetak.c: In function 'main':
sazetak.c:37:36: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   37 |   aa[b] = lcm(aa[b & -b], aa[b & b - 1]);
      |                                  ~~^~~
sazetak.c:38:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   38 |   kk[b] = kk[b & b - 1] + 1;
      |                  ~~^~~
sazetak.c:31:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d%d", &a, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
sazetak.c:33:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", &aa[1 << i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 269 ms 256 KB Output is correct
4 Correct 106 ms 264 KB Output is correct
5 Correct 111 ms 260 KB Output is correct
6 Execution timed out 1087 ms 204 KB Time limit exceeded
7 Execution timed out 1083 ms 204 KB Time limit exceeded
8 Execution timed out 1084 ms 204 KB Time limit exceeded
9 Execution timed out 1095 ms 204 KB Time limit exceeded
10 Execution timed out 1081 ms 204 KB Time limit exceeded