百练 Let it Bead

总时间限制: 内存限制:
1000ms 65536kB

描述

“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.

输入

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.

输出

For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.

样例输入

1 1
2 1
2 2
5 1
2 5
2 6
6 2
0 0

样例输出

1
2
3
5
8
13
21

#include <cstdio>using namespace std;int gcd(int a, int b) {return b ? gcd(b, a % b) : a;
}int main() {// c种颜色,链子长为sint c, s;while(scanf("%d%d", &c, &s) == 2 && c != 0) {long long p[s + 10];p[0] = 1;// power of cfor(int k = 0; k < s; k++) {p[k + 1] = p[k] * c;}// reflection partlong long counts = s & 1 ? s * p[s / 2 + 1] :(s / 2) * (p[s / 2] + p[s / 2 + 1]);// rotation partfor(int k = 1; k <= s; k++) {counts += p[gcd(k, s)];}counts /= 2 * s;printf("%d\n", counts);}return 0;
}

百练 Let it Bead相关推荐

  1. 百练,4103,踩方格

    百练,4103,踩方格 普通做法:(也可以找规律) #include #include//要调用memset函数,头文件 using namespace std; int visited[50][50 ...

  2. 北大OJ百练——4075:矩阵旋转(C语言)

    百练的这道题很简单,通过率也达到了86%,所以我也就来贴个代码了...下面是题目: 不过还是说一下我的思路: 这道题对一个新来说,可能是会和矩阵的转置相混淆,这题并不是要我们去求矩阵的转置. 这题,我 ...

  3. 威佐夫博弈:百练OJ:1067:取石子游戏

    威佐夫博弈(Wythoff's game):有两堆各若干个物品,两个人轮流从任一堆取至少一个或同时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 百练OJ:1067:取石子游戏 ...

  4. 百练OJ:4003:十六进制转十进制(python三行代码实现)

    题目链接:百练OJ:4003 描述 将十六进制数转换成十进制数 输入 第一行有一个整数T,表示共有T组数据 接下来T行,每一行为一个16进制无符号正整数,位数不超过8位,数中的a-f均为大写字母,数前 ...

  5. 百练OJ:2742:统计字符数

    题目链接: 百练OJ:2742:统计字符数 描述:判断一个由a-z这26个字符组成的字符串中哪个字符出现的次数最多 输入:第1行是测试数据的组数n,每组测试数据占1行,是一个由a-z这26个字符组成的 ...

  6. java函数实现进制转换与java实现八进制到十进制的转换(百练OJ:2735:八进制到十进制)

    java进制转换函数介绍:Java二进制.八进制.十进制.十六进制相互转换: 二进制转十进制 Integer.parseInt("0110", 2); 八进制转十进制 Intege ...

  7. 百练OJ:2973:Skew数

    题目链接: 百练OJ:2973:Skew数 描述:在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1). 每个位上的可能数字是0 或 1,最后面一个非零位可以是2, 例如, ...

  8. 百练 求排列的逆序数

    百练 求排列的逆序数 总时间限制: 内存限制: 1000ms 65536kB 描述 在Internet上的搜索引擎经常需要对信息进行比较,比如可以通过某个人对一些事物的排名来估计他(或她)对各种不同信 ...

  9. 百练 06 股票买卖

    百练 06 股票买卖 总时间限制: 内存限制: 1000ms 65536kB 描述 最近越来越多的人都投身股市,阿福也有点心动了.谨记着"股市有风险,入市需谨慎",阿福决定先来研究 ...

最新文章

  1. EasyDarwin开源社区 短视频拍摄项目Github地址
  2. 释放skb buffer指针引出的指针传递问题
  3. 在Mac下的前端开发必备工具
  4. 访问 asp网页 白屏_(02)ASP如何设定主目录和默认文档
  5. python学习之路-第七天-python面向对象编程简介
  6. 键盘输入Scanner类方法属性使用
  7. 基于JAVA+SpringMVC+MYSQL的报价管理系统
  8. IT计算机实习:JAVA实习报告范文(三)
  9. 利用xlsl.full.js导入excel表格
  10. murmur3 php,murmur: 更快更好的哈希函数
  11. 悟空问答python反爬_Python写个爬虫碰到反爬了,怎么办那就动手破坏它!
  12. 2022-2028年全球与中国SCADA石油和天然气行业发展趋势及投资战略分析
  13. 改变生物学研究进程:AI模型打开生命信息密码
  14. 杭州电子科技大学计算机录取分数线,杭州电子科技大学历年录取分数线多少及各省最低投档线统计表...
  15. 2022-2028年中国铷矿行业市场现状分析及发展前景展望报告
  16. origin刻度消失_Origin中坐标轴被误删了,怎么恢复坐标轴及刻度
  17. kubernetes自定义hosts域名解析
  18. 百囚犯问题(100 prisoners problem)
  19. 鼠标悬停“改变”图片
  20. json文件格式标准

热门文章

  1. vue实现网络图片瀑布流 + 下拉刷新 + 上拉加载更多
  2. Windows/Linux服务器上Tomcat开启远程调试,使用IDEA本地调试
  3. 【CSS】学习笔记3 段落设置
  4. 【Python】Python库之Web信息提取
  5. C#LeetCode刷题-程序员面试金典
  6. C#LeetCode刷题-堆
  7. 一些前端常用工具的生命周期
  8. 失忆症later和crowd什么关系_约惠七夕把爱给到对的人 费洛蒙香水作用危害,费洛蒙是什么东西,费洛蒙香水有用吗...
  9. c# xml添加 删除 修改数据
  10. 一个寄存器有几个字节_STM32f103ZET6 学习资料 (连载2 寄存器的操作界限)