poj 1286 Necklace of Beads poj 2409 Let it Bead HDU 3923 Invoker <组合数学>
2024-08-30 11:27:32
链接:http://poj.org/problem?id=1286
http://poj.org/problem?id=2409
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL P_M( LL a, LL b )
{
LL res=, t=a;
while (b){
if(b&)res*=t;
t*=t;
b>>=;
}
return res;
}
int a[], vi[];
void dfs( int i )
{
if( !vi[i] ){
vi[i]=;
dfs(a[i]);
}
} int find(int t, int n ) // 求循环节 s == gcd( n, t ) ;
{
memset(vi, , sizeof vi);
memset(a, , sizeof a);
for( int i=; i<=n; ++ i ){
int e=(i+t-)%n;
if( e== )e=n;
a[i]=e;
}
int s=;
for( int i=; i<=n; ++ i ){
if(!vi[i]){
dfs(i);
s++;
}
}
return s;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
int main( )
{
int N;
while( scanf("%d", &N)!= EOF){
if( N==- )break;
if( N== ){puts(""); continue;}
LL ans=;
if( !(N&) ){
ans=P_M(3LL, N);
for( int i=; i<=N; ++i ){
int t=find(i, N);
ans+=P_M( 3LL,t );
}
ans+=(LL)(N/)*(P_M(3LL,(N+)/));
ans+=(LL)(N/)*P_M(3LL,N/);
}
else{
for( int i=; i<N; ++i ){
ans+=P_M(3LL, gcd(i, N));
}
ans+=(LL)(N)*(P_M(3LL,N/+)); }
printf( "%d\n", ans/(*N) );
}
return ;
}
poj 1286
#include <cstdio>
#include <iostream>
using namespace std;
int N, M;
typedef long long LL;
LL P_M(int a, int b )
{
LL res=,t=a;
while(b){
if(b&)res*=t;
t*=t;
b>>=;
}
return res;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
LL polya( int k, int m )
{
LL ans=;
for( int i=; i<m; ++ i ){
ans+=P_M(k, gcd( i, m ));
}
if( m& ){
ans+=(LL)(m*P_M( k, m/+ ) );
}
else {
ans+=(LL)m/*P_M(k, m/);
ans+=(LL)m/*P_M(k, m/+);
}
if(m)ans/=,ans/=m;
return ans;
}
int main( )
{
while(scanf("%d%d", &N,&M)!=EOF, N+M ){
printf("%lld\n", polya(N, M));
}
return ;
}
poj 2409
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const LL M=1e9+;
LL P_M(int a, int b )
{
LL res=,t=a;
while(b){
if(b&)res*=t, res%=M;
t*=t, t%=M;
b>>=;
}
return res;
}
int gcd( int x, int y )
{
return y==?x:gcd( y, x%y );
}
LL polya( int k, int m )
{
LL ans=;
for( int i=; i<m; ++ i ){
ans+=P_M(k, gcd( i, m ));
ans%=M;
}
if( m& ){
ans+=(LL)(m*P_M( k, m/+ ) );
}
else {
ans+=(LL)m/*P_M(k, m/);
ans+=(LL)m/*P_M(k, m/+);
}
ans%=M;
return (ans*P_M(*m,M-))%M;// 求逆元
}
int main( )
{
int T, N, K, t=;
scanf("%d", &T);
while(T--){
scanf("%d%d", &N,&K);
printf("Case #%d: %I64d\n", t++, polya(N, K));
}
return ;
}
hdu 3923
最新文章
- 链式编程中的next()和end()
- switch(面试)
- 关闭 selinux 和防火墙
- 【转】Python中string的strip,lstrip,rstrip用法
- tyvj1018 - 阶乘统计 ——暴力
- shell随机写入指定文件
- JS如何获取多个相同class标签并分别再输出各自的文本
- 怎样做出优秀的扁平化设计风格 PPT 或 Keynote 幻灯片演示文稿?(装)
- Http Header Content-Disposition
- 配置Apache+Mysql+Php
- Filter与Servlet的区别和联系
- PHP数组基本排序算法和查找算法
- 统计表中 重复出现 XX次以上的数据
- 第 10 章 容器监控 - 078 - Docker 最常用的监控方案
- 01-Jenkins-Master节点安装
- 【十三】jvm 性能调优工具之 jstack
- SQL注入之Sqli-labs系列第十七关(UPDATA– 基于错误– 单引号– 字符型)
- Selector空轮询处理(转载)
- ASP.NET MVC验证码演示(Ver2)
- 使用SQL Server Management Studio操作replication时,要用机器名登录,不要用IP地址
热门文章
- Intent显示启动与隐式启动
- 【MFC】Button控件和Picture Control的鼠标事件执行顺序
- py2exe使用方法 (含一些调试技巧,如压缩email 类)
- PHP读取APK的包信息,包括包名,应用名,权限,LOGO等
- RSA 公钥加密算法
- Codeforces 597B Restaurant(离散化 + 贪心)
- luogu P3808 【模板】AC自动机(简单版)
- Maven添加坐标(依赖)及在Eclipse中的操作
- uitableview中文排序问题
- Oracle 实例名/服务名 请问SID和Service_Name有什么区别