CodeForces 610APasha and Stick(수학)

Description
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 2·109) — the length of Pasha's stick.
Output
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Sample Input
Input
6
Output
1
Input
20
Output
4
코드:
4
#include
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
	if(n%2==1)
	printf("0
"); else { if(n%4==0) printf("%d
",n/4-1); else printf("%d
",n/4); } } return 0; }
사고방식: 제목은 n을 세어 주는 것이다. n을 4부로 나누어 몇 개의 직사각형을 구성하고 정사각형이 아니냐고 묻는다.
짝수 여부를 먼저 판단하고 짝수가 아니면 안 된다.직사각형은 가장자리가 같기 때문에 n을 두 개의 짝수로 나누는 것으로 볼 수 있다. 그러면 n/4가지가 가능하다.그리고 4의 배수인지 아닌지를 판단한다. 그렇다면 답안은 1개를 빼고 아니면 바로 출력한다.

좋은 웹페이지 즐겨찾기