Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // math way
- int arr[100005];
- long long int cnt[10005];
- int main(){
- int N;
- long long int total = 0;
- scanf("%d", &N);
- for(int i = 0; i < N; i++){
- scanf("%d", &arr[i]);
- cnt[arr[i]]++;
- //printf("cnt[%d] = %d\n", arr[i], cnt[arr[i]]);
- }
- for(int i = 0; i < 10001; i++){
- if(cnt[i] <= 1) continue;
- else {
- // if there are more than one, e.g 5 of the same number
- // it is the same as (5 2) 5 C 2 which is 5 * 4 / 2
- total += (cnt[i]* (cnt[i] - 1)) /2;
- }
- }
- printf("%lld\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement