C. Polygon for the Angle

You are given an angle angang.

The Jury asks You to find such regular nn-gon (regular polygon with nn vertices) that it has three vertices aa, bb and cc (they can be non-consecutive) with ∠abc=ang∠abc=ang or report that there is no such nn-gon.

If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353998244353.

Input

The first line contains single integer TT (1≤T≤1801≤T≤180) — the number of queries.

Each of the next TT lines contains one integer angang (1≤ang<1801≤ang<180) — the angle measured in degrees.

Output

For each query print single integer nn (3≤n≤9982443533≤n≤998244353) — minimal possible number of vertices in the regular nn-gon or −1−1 if there is no such nn.

思路:模拟:最少三个点才能有角度,所以从3开始模拟

#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define mod 998244353
using namespace std;
double n;
int main(){
    int t;
    cin>>t;
    while(t--){
        cin>>n;int i,f=0;
        for(i=3;i<400;i++){
            double du=360.0/i;
            for(int j=1;j<i-1;j++){//i-1表示若分为i份,最多i-2个组成角度
                int a=(int)j*du/2;
                if(a==n){
                    f=1;
                    break;
                }
            }
            if(f)break;
        }
        cout<<i<<endl;
    }
    return 0;
}

使用gcd,求出和180的最大公约数,

#include<bits/stdc++.h>
using namespace std;
int T,n,ans;
int main(){
	cin>>T;
	while(T--){
		cin>>n;
		int zz=__gcd(n,180);
		zz=180/zz;
		while(180*(zz-2)/zz<n) zz*=2;
		cout<<zz<<endl;
	}
	return 0;
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值