Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // 나머지 합
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdbool.h>
  6. #include <math.h>
  7. #include <limits.h>
  8. #define MAX 1002
  9.  
  10. int main(){
  11.  
  12. int N, M, A;
  13. long long sum = 0, Ans = 0;
  14. long long count[1000] = { 1 };
  15.  
  16. scanf("%d %d", &N, &M);
  17. while( N-- ){
  18. scanf("%d", &A);
  19. sum += A;
  20. count[ sum = sum%M ]++;
  21. }
  22. while( M-- ){
  23. Ans += (count[M]-1) * (count[M]) / 2;
  24. }
  25. printf("%lld", Ans);
  26. return 0;
  27. }
  28.  
  29.  
  30.  
  31. 0 1 2 6 + 1 = 7
  32. 4 2 0
  33.  
  34. 0 : 1, { 1, 2 }, { 1, 2, 3 }, { 1, 2, 3, 1, 2 }
  35. 1 : { 1 }, { 1, 2, 3, 1 }
  36.  
  37. 1에서 경우의 수
  38. { 1, 2, 3, 1 } - { 1 } = 1+2+3 = 6, 6%3 == 0
  39.  
  40. 0에서 경우의 수
  41. { 1, 2 }, { 1, 2, 3 }, { 1, 2, 3, 1, 2 }
  42. { 1, 2, 3 } - { 1, 2 } = 3, 3%3 == 0
  43. { 1, 2, 3, 1, 2 } - { 1, 2 } = 3+1+2 = 6, 6%3 == 0
  44. { 1, 2, 3, 1, 2 } - { 1, 2, 3 } = 1+2 = 3. 3%3 == 0
  45.  
  46. ========================================================
  47. 실제 표현은?
  48.  
  49. Input : 5 3
  50. 1 2 3 1 2
  51.  
  52. Ans : ( 1, 2 ), ( 1, 3 ), ( 1, 5 ), ( 3, 3 ), ( 4, 5 )
  53. ( 2, 4 ), ( 3, 5 ) = 7개
  54.  
  55. ( 1, 2 ) -> { 1, 2 } 앞에 있는 1, 2임
  56. ( 1, 3 ) -> { 1, 2, 3 }
  57. ( 1, 5 ) -> { 1, 2, 3, 1, 2 }
  58. ( 3, 3 ) -> { 3 }
  59. ( 4, 5 ) -> { 1, 2 } 뒤에 있는 1, 2임
  60. ( 2, 4 ) -> { 2, 3, 1 }
  61. ( 3, 5 ) -> { 3, 1, 2 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement