Codeforces Round #652 (Div. 2) #A. FashionabLee

A.FashionabLee
time limit per test2 seconds
memory limit per test256 megabytes
input:standard input
output:standard output

Lee is going to fashionably decorate his house for a party, using some regular convex polygons.

Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis at the same time.

Recall that a regular n-sided polygon is a convex polygon with n vertices such that all the edges and angles are equal.

Now he is shopping: the market has t regular polygons. For each of them print YES if it is beautiful and NO otherwise.

Input

The first line contains a single integer t ( 1 ≤ t ≤ 1 0 4 1≤t≤10^4 1t104) — the number of polygons in the market.

Each of the next t lines contains a single integer ni ( 3 ≤ n i ≤ 1 0 9 3≤n_i≤10^9 3ni109): it means that the i-th polygon is a regular n i n_i ni-sided polygon.

Output

For each polygon, print ‘YES’ if it’s beautiful or NO otherwise (case insensitive).

Example

  • Input:
    4
    3
    4
    12
    1000000000

  • Output:
    NO
    YES
    YES
    YES

  该题题意为给出正多边形的边数,判断该正多边形是否可以满足有一边平行于x轴,一边平行于y轴,即满足有两边互相垂直即可。
  这是一个纯粹的数学问题,通过求解正多边形的每一个内角和对应的外角 θ \theta θ,若满足外角 θ \theta θ恰好能被90°整除,则满足条件,但是注意到外角不都为整数,比如边为11时得到的外角 θ \theta θ为32.72°,此时无法用取模来判断是否可以被90°整除。
  于是注意到外角 θ \theta θ可以被90°整除时,自然也可以被180°整除,通过第一条平行于x轴的边可以分别得到两条垂直于x轴的边,两条平行于x轴的边,易知这四条边恰好关于正多边形为中心对称,根据对称性,当且仅当正多边形的边数n为4的倍数时得解。
代码如下:

#include<iostream>
using namespace std;
void solve();
int main()
{
	int t;
	cin>>t;
	while(t--)
		solve();
	return 0;
}
void solve()
{
	int n;
	cin>>n;
	if(n%4==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

  这道题的代码很简单,但是解题思路才是学习的最重要的部分,有了数学思维,学习程序才能设计出更加高效的代码。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值