POJ 2409
水题一道,不加优化也能0MS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
} int Power(int a,int b){
int ans=1;
while(b){
if(b&1) ans=(ans*a);
a=a*a;
b>>=1;
}
return ans;
} int main(){
int c,s;
while(scanf("%d%d",&c,&s),c||s){
int ans=0;
for(int i=1;i<=s;i++){
ans=ans+Power(c,gcd(i,s));
}
if(s&1){
ans=ans+s*Power(c,s/2+1);
}
else{
ans=ans+(s/2)*(Power(c,s/2+1)+Power(c,s/2));
}
ans/=(2*s);
printf("%d\n",ans);
}
return 0;
}
POJ 2409的更多相关文章
- poj 2409+2154+2888(Burnside定理)
三道burnside入门题: Burnside定理主要理解置换群置换后每种不动点的个数,然后n种不动点的染色数总和/n为answer. 对于旋转,旋转i个时不动点为gcd(n,i). 传送门:poj ...
- poj 1286 Necklace of Beads & poj 2409 Let it Bead(初涉polya定理)
http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...
- bzoj 1004 [HNOI2008]Cards && poj 2409 Let it Bead ——置换群
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 http://poj.org/problem?id=2409 学习材料:https:/ ...
- poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
链接:http://poj.org/problem?id=1286 http://poj.org/problem?id=2409 #include <cstdio> #include &l ...
- POJ 2409 Let it Bead(polay计数)
题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...
- poj 2409 Let it Bead && poj 1286 Necklace of Beads(Polya定理)
题目:http://poj.org/problem?id=2409 题意:用k种不同的颜色给长度为n的项链染色 网上大神的题解: 1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1. ...
- POJ 2409 Let it Bead 组合数学
题目地址: http://poj.org/problem?id=2409 给你一串珠子有m个,用n种不同的颜色涂色,问有多少种分法. 用polay定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- 【POJ 2409】Let it Bead
http://poj.org/problem?id=2409 Burnside引理:设\(G\)是\(X\)的置换群,而\(\mathcal{C}\)是\(X\)中一个满足下面条件的着色集合:对于\( ...
- POJ 2409 Let it Bead:置换群 Polya定理
题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...
随机推荐
- LOJ——#2256. 「SNOI2017」英雄联盟
https://loj.ac/problem/2256 题目描述 正在上大学的小皮球热爱英雄联盟这款游戏,而且打的很菜,被网友们戏称为「小学生」.现在,小皮球终于受不了网友们的嘲讽,决定变强了,他变强 ...
- [MongoDB实战]Part1 起步
本书的这部分对MongoDB进行了一个大致的简介.包括了Javascript Shell和Ruby驱动,这俩都有例子 在第一章,我们将了解到MongoDB的历史,设计目的和实际使用的场景.我们还将了解 ...
- android 九宫格(16宫格)控件
public class NineRectView extends ViewGroup { private Context ctx; private int wSize,hSize,row,colum ...
- PHP生成二维码的2种方式
二维码的用处俺也就不说了,看一下用PHP生成的二维码吧. 利用谷歌提供的API 生成二维码,如今非常多国外站点都提供了这类API 看下代码吧<=======================> ...
- Java中使用多线程、curl及代理IP模拟post提交和get訪问
Java中使用多线程.curl及代理IP模拟post提交和get訪问 菜鸟,多线程好玩就写着玩.大神能够路过不吝赐教.小弟在这受教.谢谢! 很多其它分享请关注微信公众号:lvxing1788 ~~~~ ...
- ExtJs--16--Ext.override()方法专门用来重写对象的方法
Ext.onReady(function(){ /** * Ext.override()方法专门用来重写对象的方法 */ //定义个类 Ext.define("U",{ //该类的 ...
- poj--3159--Candies(简单差分约束)
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 26888 Accepted: 7398 Descrip ...
- SQL语句之Insert
插入常见的3种形式: 单条插入, 批量插入, 返回刚插入行的id http://www.cnblogs.com/yezhenhan/archive/2011/08/17/2142948.html
- Spring学习笔记(一) 简介
版权声明 本文是摘自IBM上Naveen Balani的一篇文章,原文请点击此处:http://www.ibm.com/developerworks/cn/java/wa-spring1/ Sprin ...
- Python—JSON数据解析
1.安装pip pip是python的包管理工具,使用它能非常方便地安装和卸载各种python工具包 第一步:直接用浏览器访问地址:https://raw.github.com/pypa/pip/ma ...