思路

同这道题,只是颜色数从3变成c

代码

#include <cstdio>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
int gcd(int a,int b){
return (b==0)?a:gcd(b,a%b);
}
int pow(int a,int b){
int ans=1;
while(b){
if(b&1)
ans=(ans*a);
a=(a*a);
b>>=1;
}
return ans;
}
int n,m;
signed main(){
while(scanf("%lld %lld",&n,&m)==2){
if(n==0&&m==0)
break;
int ans=0,cnt=0;
for(int i=0;i<m;i++){
ans=(ans+pow(n,gcd(m,i)));
cnt++;
}
if(m%2){
ans=(ans+pow(n,(m-1)/2+1)*m);
cnt+=m;
}
else{
ans=(ans+pow(n,(m-2)/2+2)*(m/2));
cnt+=(m/2);
ans=(ans+pow(n,m/2)*(m/2));
cnt+=(m/2);
}
printf("%lld\n",ans/cnt);
}
return 0;
}

POJ 2409 Let it Bead的更多相关文章

  1. poj 1286 Necklace of Beads &amp; poj 2409 Let it Bead(初涉polya定理)

    http://poj.org/problem?id=1286 题意:有红.绿.蓝三种颜色的n个珠子.要把它们构成一个项链,问有多少种不同的方法.旋转和翻转后同样的属于同一种方法. polya计数. 搜 ...

  2. 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:/ ...

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

  4. POJ 2409 Let it Bead(polya裸题)

    题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...

  5. POJ 2409 Let it Bead(polay计数)

    题目链接:http://poj.org/problem?id=2409 题意:给出一个长度为m的项链,每个珠子可以用n种颜色涂色.翻转和旋转后相同的算作一种.有多少种不同的项链? 思路: (1) 对于 ...

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

  7. POJ 2409 Let it Bead 组合数学

    题目地址: http://poj.org/problem?id=2409 给你一串珠子有m个,用n种不同的颜色涂色,问有多少种分法. 用polay定理求解,对于排成一排的带编号的小球,按照某一种方案改 ...

  8. POJ 2409 Let it Bead:置换群 Polya定理

    题目链接:http://poj.org/problem?id=2409 题意: 有一串n个珠子穿起来的项链,你有k种颜色来给每一个珠子染色. 问你染色后有多少种不同的项链. 注:“不同”的概念是指无论 ...

  9. bzoj 1004 Cards & poj 2409 Let it Bead —— 置换群

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1004 关于置换群:https://www.cnblogs.com/nietzsche-oie ...

  10. POJ 2409 Let it Bead(Polya定理)

    点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...

随机推荐

  1. Java多线程-----匿名内部类创建线程

       1.继承Thread类创建线程 package com.practise.createthread; public class AnonymousThread { public static v ...

  2. Spring tokenizeToStringArray

    tokenizeToStringArray: StringUtils.tokenizeToStringArray(pattern, this.pathSeparator, this.trimToken ...

  3. python中函数嵌套、函数作为变量以及闭包的原理

    嵌套函数: python允许创建嵌套函数.也就是说我们可以在函数里面定义函数,而且现有的作用域和变量生存周期依旧不变. 例子: #encoding=utf-8 def outer():    name ...

  4. Linux服务器---邮件服务openwebmail安装

    安装openwebmail  openwebmail提供了可视化的邮件管理系统,它运行在Apache环境下. 1.安装必备软件 [root@localhost ~]# yum install –y p ...

  5. 51Nod 1090 3个数和为0

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1090 思路:排序 三个for循环 但是要控制循环 不能从头开 ...

  6. [转载]oracle 数据类型详解---日期型

    1.常用日期型数据类型1.1.DATE这是ORACLE最常用的日期类型,它可以保存日期和时间,常用日期处理都可以采用这种类型.DATE表示的日期范围可以是公元前4712年1月1日至公元9999年12月 ...

  7. Django框架----路由系统、视图和模板(简单介绍)

    一.路由配置系统(urls) URL配置(URLconf)就像Django所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表: 你就是以这种方式告诉Django,对于这个URL ...

  8. 怎样从外网访问内网SQLServer数据库?

    本地安装了一个SQLServer数据库,只能在局域网内访问到,怎样从外网也能访问到本地的SQLServer数据库呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动SQLServer数据 ...

  9. ConvertUtils.register(new DateConverter(null), java.util.Date.class)使用

    在我们使用BeanUtils.copyProperties(dest,orig)将一个类的属性赋值给另一个类的时候 如果类中存在 Date类型的转换可能会报"no value specifi ...

  10. STM32L476应用开发之六:电池SOC检测(转)

    源: STM32L476应用开发之六:电池SOC检测