Manioc

dp combinações divisveis

Aug 9th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX 1000007
  3.  
  4. using namespace std;
  5.  
  6. long long arr[MAX], n;
  7. long long dp[MAX];
  8.  
  9. int main(){
  10.     scanf("%d", &n);
  11.  
  12.     for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
  13.  
  14.     long long ans = 0, sum = 0;
  15.     dp[0] = 1;
  16.     for(int i = 0; i < n; i++){
  17.         sum = (sum+arr[i])%8;// modulo que vc quer as combinações
  18.         ans += dp[sum];
  19.  
  20.         dp[sum]++;
  21.     }
  22.     cout << ans << endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment