Created
October 29, 2018 19:04
-
-
Save mvallebr/ff3983ef9a05acfdcf653cdaf2df460a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3 | |
| import math | |
| import os | |
| import random | |
| import re | |
| import sys | |
| from collections import defaultdict | |
| # Complete the countTriplets function below. | |
| def countTriplets(arr, r): | |
| v2 = defaultdict(int) | |
| v3 = defaultdict(int) | |
| count = 0 | |
| for k in arr: | |
| count += v3[k] | |
| v3[k*r] += v2[k] | |
| v2[k*r] += 1 | |
| return count | |
| if __name__ == '__main__': | |
| fptr = open(os.environ['OUTPUT_PATH'], 'w') | |
| nr = input().rstrip().split() | |
| n = int(nr[0]) | |
| r = int(nr[1]) | |
| arr = list(map(int, input().rstrip().split())) | |
| ans = countTriplets(arr, r ) | |
| fptr.write(str(ans) + '\n') | |
| fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment