Created
April 29, 2014 12:24
-
-
Save chomado/11398690 to your computer and use it in GitHub Desktop.
This file contains 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
#include <stdio.h> | |
int check(int, int, int, int); | |
int solve(int, int); | |
/***** メイン関数 *****/ | |
int main(void) | |
{ | |
int n, sum; | |
while (scanf("%d %d", &n, &sum), n||sum) { | |
printf("%d\n", solve(n, sum)); | |
} | |
return 0; | |
} | |
/***** 関数群 *********/ | |
int check(int a, int b, int c, int sum) | |
{ | |
return (a+b+c==sum) ? 1 : 0; | |
} | |
int solve(int n, int sum) | |
{ | |
int i, j, k; | |
int counter = 0; | |
for (i=1; i<=n-2; i++) | |
for (j=i+1; j<=n-1; j++) | |
for (k=j+1; k<=n; k++) | |
if (check(i, j, k, sum)) counter++; | |
return counter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment