Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 나머지 합
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- #include <math.h>
- #include <limits.h>
- #define MAX 1002
- int main(){
- int N, M, A;
- long long sum = 0, Ans = 0;
- long long count[1000] = { 1 };
- scanf("%d %d", &N, &M);
- while( N-- ){
- scanf("%d", &A);
- sum += A;
- count[ sum = sum%M ]++;
- }
- while( M-- ){
- Ans += (count[M]-1) * (count[M]) / 2;
- }
- printf("%lld", Ans);
- return 0;
- }
- 0 1 2 6 + 1 = 7
- 4 2 0
- 0 : 1, { 1, 2 }, { 1, 2, 3 }, { 1, 2, 3, 1, 2 }
- 1 : { 1 }, { 1, 2, 3, 1 }
- 1에서 경우의 수
- { 1, 2, 3, 1 } - { 1 } = 1+2+3 = 6, 6%3 == 0
- 0에서 경우의 수
- { 1, 2 }, { 1, 2, 3 }, { 1, 2, 3, 1, 2 }
- { 1, 2, 3 } - { 1, 2 } = 3, 3%3 == 0
- { 1, 2, 3, 1, 2 } - { 1, 2 } = 3+1+2 = 6, 6%3 == 0
- { 1, 2, 3, 1, 2 } - { 1, 2, 3 } = 1+2 = 3. 3%3 == 0
- ========================================================
- 실제 표현은?
- Input : 5 3
- 1 2 3 1 2
- Ans : ( 1, 2 ), ( 1, 3 ), ( 1, 5 ), ( 3, 3 ), ( 4, 5 )
- ( 2, 4 ), ( 3, 5 ) = 7개
- ( 1, 2 ) -> { 1, 2 } 앞에 있는 1, 2임
- ( 1, 3 ) -> { 1, 2, 3 }
- ( 1, 5 ) -> { 1, 2, 3, 1, 2 }
- ( 3, 3 ) -> { 3 }
- ( 4, 5 ) -> { 1, 2 } 뒤에 있는 1, 2임
- ( 2, 4 ) -> { 2, 3, 1 }
- ( 3, 5 ) -> { 3, 1, 2 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement