poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286
真·Polya定理模板题;
写完以后感觉理解更深刻了呢。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int n;
ll ans;
ll pw(ll a,int b)
{
ll ret=;
for(;b;b>>=,a*=a)
if(b&)ret*=a;
return ret;
}
int gcd(int a,int b){return (a%b==)?b:gcd(b,a%b);}
ll rot(int n)
{
ll ret=;
for(int i=;i<n;i++)
ret+=pw(,gcd(i,n));
return ret;
}
ll d(int n)
{
if(n%)return (ll)n*pw(,(n-)/+);
return (ll)n/*(pw(,n/)+(ll)pw(,(n-)/+));
}
int main()
{
while()
{
scanf("%d",&n);
if(!n)
{
printf("0\n"); continue;//!
}
if(n==-)return ;
ans=(rot(n)+d(n))/(*n);
printf("%lld\n",ans);
}
}
poj1286 Necklace of Beads—— Polya定理的更多相关文章
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- Necklace of Beads(polya定理)
http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...
- 【数论】【Polya定理】poj1286 Necklace of Beads
Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- Necklace of Beads(polya计数)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7451 Accepted: 3102 ...
- hdu 1817 Necklace of Beads (polya)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- poj1286 Necklace of Beads【裸polya】
非常裸的polya,只是我看polya看了非常久 吉大ACM模板里面也有 #include <cstdio> #include <cmath> #include <ios ...
- POJ1286 Necklace of Beads
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8263 Accepted: 3452 Description Beads ...
- POJ2154 Color【 polya定理+欧拉函数优化】(三个例题)
由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问 ...
随机推荐
- assert.ifError()函数详解
assert.ifError(value) 如果 value 为真值时,抛出 value.当测试在回调函数里的参数 error 时非常有用. const assert = require('asser ...
- LeetCode(54)Spiral Matrix
题目 Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral ...
- map.keySet()获取map全部的key值
map.keySet()获取map全部的key值 public static String getUrlWithQueryString(String url, Map<String, Str ...
- CSU 1259 bfs找最短路
题目大意: 不想介绍,题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1259 bfs求最短路. 这里因为2-9,到达同样的点不计步数,那我 ...
- [K/3Cloud] 创建一个操作校验器
概念: 定义了一个校验器对象,通常是添加到业务单据操作服务插件,用于对操作的合法性进行校验.继承自校验器抽象对象AbstractValidator. 示例: 新建一个类,继承自AbstractVali ...
- 【NOIP2017】宝藏(状压DP)
题意: 思路:n<=12,考虑状压DP 生成树中深度相同的点可以一次性转移完毕 设dp[sta,i]为已转移完sta状态的点,当前深度为i的最小花费 dp[sta or v,i+1]=min(d ...
- cogs——1364. 聚会
1364. 聚会 ★ 输入文件:partyb.in 输出文件:partyb.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 小S想要从某地出发去同学k的家中参加 ...
- HDU——3072 Intelligence System
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Subsets and Subsets II (回溯,DFS,组合问题)
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- javaweb开发页面数字过长显示科学计数法的问题
1. 检查该字段是否为double类型,如果是,请改成BigDecimal 2.如果是导出excel里面为科学计数法,原页面正常,是因为excel设置的原因,请参考https://jingyan.ba ...