URAL 1982 Parallel and Perpendicular

来源:互联网 发布:芈月传 大秦帝国 知乎 编辑:程序博客网 时间:2024/04/26 13:04
You are given a regular n-gon. Your task is to calculate two values: the number of its diagonals that are parallel to at least one of its other diagonals, and the number of its diagonals that are perpendicular to at least one of its diagonals. A diagonal is a segment connecting two non-adjacent polygon vertices.

Input

The only line contains an integer n (4 ≤ n ≤ 105).

Output

Output two required numbers.

Sample


题意:给一个正n边形,求正n边行的对角线中,相互平行相互垂直的对角线有几条(注:相邻的顶点的边不是对角线)

题解:数学题一般由两种解法,一种是找规律,另一种是公式。先把正4-10边行的情况列出来,

          n边形            平行         垂直

          4               0           2

          5               0           0

          6               6           9

          7               14          0

          8               20          20

          9               27          0

         10               35          35

由此可得 n为偶数时,都可以找到平行和垂直的对角线

      n为奇数时,不可能找到垂直的线。

其中n=5 6 7时为特殊情况,其他的推出  平行=垂直=n*(n-3)/2

#include <cstdio>  #include <cmath>  #define LL __int64                   //__int64是Win32平台编译器64位长整型的定义方式int main()  {      LL n;                           //定义一个长型的n,表示n为大整数    while(~scanf("%I64d",&n))      {          LL num = n*(n-3)/2;//对角线条数          if(n == 4)          {              printf("0 2\n");              continue;          }          if(n == 5)          {              printf("0 0\n");              continue;          }          if(n == 6)          {              printf("6 9\n");              continue;          }          if(n%2)//边形为奇数          {              printf("%I64d 0\n",num);//不可能有垂直的,画图就知道了          }          else//边形偶数的都可以找到互相平行和垂直的          {              printf("%I64d %I64d\n",num,num);          }      }      return 0;  }  


       

0 0