A - Pair
Time limit : 2sec / Memory limit : 1024MB
Score : 100 points
Problem Statement
Find the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.
Constraints
2≤K≤100
K is an integer.
Input
Input is given from Standard Input in the following format:
K
Output
Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).
Sample Input 1
3
Sample Output 1
2
Two pairs can be chosen: (2,1) and (2,3).
Sample Input 2
6
Sample Output 2
9
Sample Input 3
11
Sample Output 3
30
Sample Input 4
50
Sample Output 4
625
#include <stdio.h>
#include <math.h>
int main()
{
int K, i, EvenNum, OddNum;
EvenNum = OddNum = 0;
scanf("%d",&K);
for(i=1;i<=K;i++){
if(i%2 == 0)
EvenNum++;
else
OddNum++;
}
printf("%d\n",EvenNum * OddNum);
return 0;
}
B - Ruined Square
Time limit : 2sec / Memory limit : 1024MB
Score : 200 points
Problem Statement
There is a square in the xy-plane. The coordinates of its four vertices are (x1,y1),(x2,y2),(x3,y3) and (x4,y4) in counter-clockwise order. (Assume that the positive x-axis points right, and the positive y-axis points up.)
Takahashi remembers (x1,y1) and (x2,y2), but he has forgot (x3,y3) and (x4,y4).
Given x1,x2,y1,y2, restore x3,y3,x4,y4. It can be shown that x3,y3,x4 and y4 uniquely exist and have integer values.
Constraints
|x1|,|y1|,|x2|,|y2|≤100
(x1,y1) ≠ (x2,y2)
All values in input are integers.
Input
Input is given from Standard Input in the following format:
x1 y1 x2 y2
Output
Print x3,y3,x4 and y4 as integers, in this order.
Sample Input 1
0 0 0 1
Sample Output 1
-1 1 -1 0
(0,0),(0,1),(−1,1),(−1,0) is the four vertices of a square in counter-clockwise order. Note that (x3,y3)=(1,1),(x4,y4)=(1,0) is not accepted, as the vertices are in clockwise order.
Sample Input 2
2 3 6 6
Sample Output 2
3 10 -1 7
Sample Input 3
31 -41 -59 26
Sample Output 3
-126 -64 -36 -131
#include <stdio.h>
int main()
{
int x1, y1, x2, y2, x3, y3, x4, y4;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
x3 = x2 - (y2 - y1);
y3 = y2 + (x2 - x1);
x4 = x3 - (y3 - y2);
y4 = y3 + (x3 - x2);
printf("%d %d %d %d",x3,y3,x4,y4);
return 0;
}
C - Triangular Relationship
Time limit : 2sec / Memory limit : 1024MB
Score : 300 points
Problem Statement
You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same.
Constraints
1≤N,K≤2×105
N and K are integers.
Input
Input is given from Standard Input in the following format:
N K
Output
Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
Sample Input 1
3 2
Sample Output 1
9
(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.
Sample Input 2
5 3
Sample Output 2
1
Sample Input 3
31415 9265
Sample Output 3
27
Sample Input 4
35897 932
Sample Output 4
114191
#include <stdio.h>
int main(){
int N,K;
scanf("%d %d",&N,&K);
long ans,x = N / K ,y = (N + K / 2) / K;
if(K % 2 == 0){
ans = x * x * x + y * y * y;
}else{
ans = x * x * x;
}
printf("%ld",ans);
return 0;
}