poj 2049 Let it Bead(polya模板)
2015-09-01 18:54
330 查看
Description
Input
Output
View Code
"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced. A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.
Input
Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.
Output
#include <iostream> using namespace std; #define LL long long int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } LL power(LL p, LL n) { LL sum = 1; while (n) { if (n & 1) sum *= p; p *= p; n /= 2; } return sum; } ///////////////////////////SubMain////////////////////////////////// int main() { LL n; LL m; while (~scanf("%I64d%I64d", &m,&n) && n+m!=0) { LL count = 0; for (int i = 1; i <= n; ++i) count += power(m, gcd(i, n)); if (n & 1) count += n * power(m, n / 2 + 1); else count += n / 2 * (power(m, n / 2 + 1) + power(m, n / 2)); count /= n * 2; printf("%lld\n", count); } return 0; }
View Code
相关文章推荐
- (1.2.4.2)寻找两个有序数组中的第K个数或者中位数
- java的访问权限
- hdu 4349 Xiao Ming's Hope,lucas定理
- Android UI设计小知识——Nine-Patch图片
- 汪潮涌 李亦非
- 转:jmeter性能测试---登录百度进行搜索
- asp.net 简单实现禁用或启用页面中的某一类型的控件
- Gson使用简要笔记
- BZOJ 3436: 小K的农场 差分约束
- MVC 自定义AuthorizeAttribute实现权限管理
- 深入讲解CSS中盒模型的用法
- 作为一个面试官,我会这样问问题——面试攻略之见招拆招
- CSDN Markdown 模板
- 数据结构——单人名单
- 数学:完全独立于实际场景的情况下定义的概念,可以正确的描述世界
- 华为oj: 提取不重复的整数
- h.264 基本知识
- linux查询rpm包详细信息
- hot code replace failed
- Java的异常处理