atcoder 競プロ典型90問 046 - I Love 46(★3)
2022.12.11
問題
方針
- 合同式(mod)で考える
- ( a % 46 + b % 46 + c % 46 ) % 46 が 0 なら割り切れる
- a, b, cで、forを三重ループしても、0から45までだからTLEならない
pythonn = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a_b = {} a = [ v % 46 for v in a ] b = [ v % 46 for v in b ] c = [ v % 46 for v in c ] a_dict = {} b_dict = {} c_dict = {} for i in range(n): a_dict[a[i]] = a_dict.get(a[i], 0) + 1 for i in range(n): b_dict[b[i]] = b_dict.get(b[i], 0) + 1 for i in range(n): c_dict[c[i]] = c_dict.get(c[i], 0) + 1 ans = 0 for i in range(46): for j in range(46): for k in range(46): if (i + j + k) % 46 == 0: ans += a_dict.get(i, 0) * b_dict.get(j, 0) * c_dict.get(k, 0) print(ans)