sgu 246 分类: sgu 2015-06...
2015-06-27 13:40
176 查看
原文链接:https://www.geek-share.com/detail/2646383600.html
一道好题。
把距离为 n+1的珠子连边,一共有 gcd(2∗n−1,n+1) 个联通块,
每个联通块的大小为 2∗n−1gcd(2∗n−1,n+1),
所以每个联通块最多可以有⌊(2∗n−1)gcd(2∗n−1,n+1)∗2⌋ 颗黑色珠子。
那么 ans=⌊(2∗n−1)gcd(2∗n−1,n+1)∗2⌋∗gcd(2∗n−1,n+1)+1
#include<cstdio> #include<cstdlib> #include<ctime> #include<cmath> #include<cstring> #include<map> #include<string> #include<stack> #include<queue> #include<utility> #include<iostream> #include<algorithm> int gcd(int a,int b) { return b?gcd(b, a%b):a; } int main() { int n, m, cnt, L; #ifndef ONLINE_JUDGE freopen("sgu246.in","r",stdin); freopen("sgu246.out","w",stdout); #endif std::cin >> m; n = ((unsigned int)m + 1)>>1; cnt = gcd(m, n+1), L = m/cnt; std::cout << (long long)cnt*(L>>1)+1; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
转载于:https://www.cnblogs.com/dashgua/p/4722984.html
相关文章推荐
- sgu 246 分类: sgu 2015-06-27 13:40 20人阅读 评论(0) 收藏
- [1,2,3,4,5,6,7,8] 转换成 [(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8)] 分类: python 2013-02-20 13:25 246人阅读 评论(1) 收藏
- sgu 181 分类: sgu 2015-03-08 11:29 36人阅读 评论(0) 收藏
- SGU 分类(转)
- sgu143 分类: sgu 2015-03-11 22:11 38人阅读 评论(0) 收藏
- sgu131 分类: sgu 2015-03-13 22:27 32人阅读 评论(0) 收藏
- #小练习 HTMLParser 分类: python 小练习 python 2013-06-03 15:54 162人阅读 评论(0) 收藏
- Android 中查看内存的使用情况集常用adb命令 标签: Androidadb 2014-06-28 10:55 57206人阅读 评论(0) 收藏 举报 分类: Android(9) 版权声
- sgu 214 分类: sgu 2015-06-20 21:11 31人阅读 评论(0) 收藏
- 史上最全的SGU题目分类
- sgu 120 分类: sgu 2015-02-09 17:19 106人阅读 评论(0) 收藏
- sgu 128 分类: sgu 2015-03-13 13:56 44人阅读 评论(0) 收藏
- sgu206 分类: sgu 2015-06-10 17:00 29人阅读 评论(0) 收藏
- Flip Game 分类: POJ 2015-06-15 14:59 22人阅读 评论(0) 收藏
- sgu 219 分类: sgu 2015-06-23 13:39 16人阅读 评论(0) 收藏
- Fibonacci Again 分类: HDU 2015-06-26 11:05 13人阅读 评论(0) 收藏
- sgu 246
- sgu 题目分类
- SGU 分类
- sgu 148 分类: sgu 2015-03-11 13:14 49人阅读 评论(0) 收藏