Description

给定一个角度 \(\theta\),请你寻找一个正 \(n\) 边型,满足在这个正 \(n\) 边型上找三个顶点 \(A,B,C\) (可以不相邻),使得 \(\angle ABC~=~\theta\) 。请输出最小的 \(n\)。保证 \(n\) 不超过 \(998244353\)。多组数据。

注意给出的 \(\theta\) 是使用角度制表示的。

Input

第一行是数据组数 \(T\)

下面 \(T\) 行,每行一个整数 \(\theta\),代表给出的角度

Output

对于每组数据输出一行代表答案

Hint

\(1~\leq~T~\leq~180~,~1~\leq~\theta~<~180\)。

Solution

多边形内角和定理:

对于一个有 \(n\) 个顶点的凸多边形 \(n~\geq~3\),其内角和为 \((n~-~2)~\times~180^\circ\)。

证明略。这大概是初中定理吧……大概方法是显然一个 \(n\) 边型可以分成 \((n~-~2)\) 个三角形,每个三角形的内角和是 \(180^\circ\)。至于证明可以分成 \((n~-~2)\) 个三角形,对 \(n\) 做数学归纳即可。

由于这是一个正 \(n\) 边型,所以一个角的度数为 \(\frac{n-2}{n}~\times~180^\circ\)

同时它连向其他每个顶点的线段平分这个角,所以它连向相邻两个顶点的线段组成的角的度数为 \(\frac{n-2}{(n-2)n}~\times~180^\circ~=~\frac{1}{n}~\times~180^\circ\)

我们设选择的点 \(A\) 和点 \(C\) 中间相隔了 \((k-1)\) 个顶点 \((k~\leq~n~-~2)\),于是这些一共组成了 \(k\) 个角度如上的角。列得方程如下(角度略去):

\[\frac{k}{n}~\times~180~=~\theta
\]

移项得

\[k~\times~180~=~\theta~\times~n
\]

我们设 \(s~=~\gcd(\theta~,~180)\),然后等式两侧同除 \(s\),得

\(\frac{180}{s}~\times~k~=~\frac{\theta}{s}~\times~n\)

由于\(\frac{180}{s}~\perp~\frac{\theta}{s}\),所以 \(k~=~\frac{\theta}{s}~,~n~=~\frac{180}{s}\)

考虑这种情况下我们要求 \(k~\leq~n~-~2\),但是如果算出来不是这样怎么办:如果答案为 \(n\) 时满足上式,则答案为 \(xn(x~\in~Z^+)\) 时一定也满足上式。于是我们不断加 \(n\) 直到合法即可。

Code

#include <cstdio>
#ifdef ONLINE_JUDGE
#define freopen(a, b, c)
#endif
#define rg register
#define ci const int
#define cl const long long typedef long long int ll; namespace IPT {
const int L = 1000000;
char buf[L], *front=buf, *end=buf;
char GetChar() {
if (front == end) {
end = buf + fread(front = buf, 1, L, stdin);
if (front == end) return -1;
}
return *(front++);
}
} template <typename T>
inline void qr(T &x) {
rg char ch = IPT::GetChar(), lst = ' ';
while ((ch > '9') || (ch < '0')) lst = ch, ch=IPT::GetChar();
while ((ch >= '0') && (ch <= '9')) x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
if (lst == '-') x = -x;
} template <typename T>
inline void ReadDb(T &x) {
rg char ch = IPT::GetChar(), lst = ' ';
while ((ch > '9') || (ch < '0')) lst = ch, ch = IPT::GetChar();
while ((ch >= '0') && (ch <= '9')) x = x * 10 + (ch ^ 48), ch = IPT::GetChar();
if (ch == '.') {
ch = IPT::GetChar();
double base = 1;
while ((ch >= '0') && (ch <= '9')) x += (ch ^ 48) * ((base *= 0.1)), ch = IPT::GetChar();
}
if (lst == '-') x = -x;
} namespace OPT {
char buf[120];
} template <typename T>
inline void qw(T x, const char aft, const bool pt) {
if (x < 0) {x = -x, putchar('-');}
rg int top=0;
do {OPT::buf[++top] = x % 10 + '0';} while (x /= 10);
while (top) putchar(OPT::buf[top--]);
if (pt) putchar(aft);
} const int maxn = 200010;
const int MOD = 998244353; int n;
ll ans;
char MU[maxn]; int main() {
freopen("1.in", "r", stdin);
qr(n);
for (rg int i = 1; i <= n; ++i) do {MU[i] = IPT::GetChar();} while ((MU[i] > 'z') || (MU[i] < 'a'));
MU[0] = MU[1]; MU[n + 1] = MU[n];;
int pos = n; while (MU[pos] == MU[0]) --pos;
int k = n - pos;
for (rg int i = 1; i <= n; ++i) if (MU[i] == MU[i - 1]) {
++ans;
} else break;
ans = (ans * k) % MOD;
++ans;
for (rg int i = 1; i <= n; ++i) if (MU[i] == MU[i - 1]) ++ans; else break;
for (rg int i = n; i; --i) if (MU[i] == MU[i + 1]) ++ans; else break;
qw(ans % MOD, '\n', true);
return 0;
}

【数学】【CF1096C】 Polygon for the Angle的更多相关文章

  1. CF-1096C Polygon for the Angle

    CF-1096C Polygon for the Angle https://codeforces.com/contest/1096/problem/C 题意:给一个角度ang(1<=ang&l ...

  2. CF1096C Polygon for the Angle

    思路: 要想到正n边形中所有可能的ang为180 * k / n (1 <= k <= n - 2). 根据n = 180 * k / ang, n是大于等于3的整数,并且n >= ...

  3. C. Polygon for the Angle 几何数学

    C. Polygon for the Angle 几何数学 题意 给出一个度数 ,问可以实现的最小的n的n边形是多少 思路 由n边形的外角和是180度直接就可以算出最小的角是多少 如果给出的度数是其最 ...

  4. C. Polygon for the Angle(几何)

    题目链接:http://codeforces.com/contest/1096/problem/C 题目大意:T是测试样例,然后每一次输入一个角度,然后问你在一个n边形里面,能不能构成这个角度,如果能 ...

  5. Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题

    感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...

  6. WPF学习05:2D绘图 使用Transform进行控件变形

    在WPF学习04:2D绘图 使用Shape绘基本图形中,我们了解了如何绘制基本的图形. 这一次,我们进一步,研究如何将图形变形. 例子 一个三角形,经Transform形成组合图形: XAML代码: ...

  7. SVG的Transform使用

    SVG的Transform使用: <%@ page language="java" contentType="text/html; charset=UTF-8&qu ...

  8. Educational Codeforces Round 57 (Rated for Div. 2)

    我好菜啊. A - Find Divisible 好像没什么可说的. #include<cstdio> #include<cstring> #include<algori ...

  9. Educational Codeforces Round 57题解

    A.Find Divisible 沙比题 显然l和2*l可以直接满足条件. 代码 #include<iostream> #include<cctype> #include< ...

随机推荐

  1. python基础知识-12-模块的了解

    python其他知识目录 1.模块介绍: Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句.模块让你能够有逻辑地组织你 ...

  2. PHP Filter 函数 日常可用

    PHP Filter 函数 PHP Filesystem PHP FTP PHP Filter 简介 PHP 过滤器用于对来自非安全来源的数据(比如用户输入)进行验证和过滤. 安装 filter 函数 ...

  3. string类型和int类型之间的转换

    一.string转int 1. 使用string流 /* 字符串转整型 */ /* * istringstream:从 string 读取数据 * ostringstream:向 string 写入数 ...

  4. idea打断点是灰色的

    点击这个图标,debug的断点就是灰色的,debug功能被禁用

  5. Java面向对象程序设计

    北京电子科技学院(BESTI)                                                                                 实    ...

  6. 校友聊NABCD需求分析

    校友聊 NABCD需求分析 N:内网用户流量不够使用 A:基于局域网进行通讯 B:通讯不花费外网流量 C:目前学校还没有使用 D:将软件放在校园网,可以下载使用

  7. 1001. A+B Format (20)的解题思路以及多源代码文件的尝试编写

    前言 这几天刚学了多源代码文件的编译,因为想尝试使用一下这种方法,所以想用此编写这次作业的程序.正好可以learning by doing,在做当中学习新知识.(编译器为Dev-C++) github ...

  8. BloomFilter——大规模数据处理利器(爬虫判重)

    http://www.cnblogs.com/heaad/archive/2011/01/02/1924195.html Bloom Filter是由Bloom在1970年提出的一种多哈希函数映射的快 ...

  9. Maya学习笔记

    软件: Maya 2016 : 参考教材: Maya 2016 中文版标准教程 ; 改变视图颜色 [窗口]|[设置/首项选择]|[颜色设置]|[3D视图]: 观察视图 旋转视图 Alt + 鼠标左键 ...

  10. JDBC连接数据库代码和步骤

    JDBC连接数据库 创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序  在连接数据库之前,首先要加载想要连接的数据库的驱动,这通过java.lang.Class类的静态方法 ...