http://poj.org/problem?id=2154

题意:经典polya题

解析:差别就是项链数目不定,采用欧拉函数,求出所有情况求解即可

// File Name: poj2154.cpp
// Author: bo_jwolf
// Created Time: 2013年10月08日 星期二 17:46:30 #include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime> using namespace std; int Case;
typedef long long INT; int eular( int n ){
int i = 0;
int ans = 1;
for( int i = 2; i * i <= n; ++i ){
if( n % i == 0 ){
ans *= ( i - 1 );
n /= i;
while( n % i == 0 ){
ans *= i;
n /= i;
}
}
}
if( n > 1 )
ans *= n - 1;
return ans;
} INT power( long long a, int b, int p ){
INT ans = 1, temp = a;
while( b ){
if( b & 1 ){
ans = ( ans * a )% p;
}
b >>= 1;
a = ( a * a )% p;
}
return ans;
} INT calc( int n, int p ){
INT ans = 0;
for( int i = 1; i * i <= n; ++i ){
if( n % i == 0 ){
ans = ( ans + eular( i ) * power( n , n / i - 1, p ) ) % p;
if( i * i != n )
ans = ( ans + eular( n / i ) * power( n, i - 1, p ) ) % p;
}
}
return ans;
} int main(){
scanf( "%d", &Case );
int i, n, p;
for( int i = 1; i <= Case; ++i ){
scanf( "%d%d", &n, &p );
printf( "%I64d\n", calc( n, p ) );
} return 0;
}

Color的更多相关文章

  1. 【转】c#、wpf 字符串,color,brush之间的转换

    转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...

  2. Python为8bit深度图像应用color map

    图片中存在着色版的概念,二维矩阵的每个元素的值指定了一种颜色,因此可以显示出彩色. 迁移调色板 下述python代码将VOC数据集中的某个语义分割的图片的调色板直接应用在一个二维矩阵代表的图像上 #l ...

  3. (转)System.Drawing.Color的颜色对照表

    经常使用System.Drawing.Color, 本篇介绍一下颜色与名称及RGB值的对应关系. 1. 颜色与名称的对照表(点击下图放大看): 2. 颜色与RGB值对照表: Color.AliceBl ...

  4. 激光打印机的Color/paper, Xerography介绍

    Color Basic 看见色彩三要素: 光源,物体,视觉 加色色彩模型:R,G,B 多用于显示器 减色色彩模型:C,M,Y,K 多用于打印复印 Paper 东亚地区常用A系列标准用纸,在多功能一体机 ...

  5. 安卓工具箱:color of Style

    <?xml version="1.0" encoding="utf-8"?> <resources> <color name=&q ...

  6. UITableView 一直显示滚动条(ScrollBar Indicators)、滚动条Width(宽度)、滚动条Color(颜色)

    在 IOS 中,对 UIScrollView 的滚动条(ScrollBar Indicators)的自定义设置接口,一直都是很少的.除了能自定义简单的样式(UIScrollViewIndicatorS ...

  7. OpenCASCADE Color Scale

    OpenCASCADE Color Scale eryar@163.com Abstract. The color scale is a specialized label object that d ...

  8. Color Transfer between Images code实现

    上计算机视觉课老师布置的作业实现论文:Color Transfer between Images 基本思路是: 1.给定srcImg和targetImg 2.将RGB空间转为Lab空间 3.根据论文中 ...

  9. ZOJ Problem Set - 1067 Color Me Less

    这道题目很简单,考察的就是结构体数组的应用,直接贴代码了 #include <stdio.h> #include <math.h> typedef struct color { ...

  10. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

随机推荐

  1. odoo 的 拉式 和 推式 库链

    推式链的数据定义在  stock.location.path 表,视图定义在 “路线” 界面的 “push rules” 具体可参考  入库设置为  Receipt in 2 steps . push ...

  2. C语言-07其它相关

    预处理指令 /* 不带参数的宏定义 1.所有的预处理指令都是以#开头 2.预处理指令分3种 1> 宏定义 2> 条件编译 3> 文件包含 3.预处理指令在代码翻译成0和1之前执行 4 ...

  3. Python3实现连接SQLite数据库的方法

    本文实例讲述了Python3实现连接SQLite数据库的方法,对于Python的学习有不错的参考借鉴价值.分享给大家供大家参考之用.具体方法如下: 实例代码如下: ? 1 2 3 4 5 6 7 8 ...

  4. c# 之 New新知

    本人从事.NET工作已经一段时间,毕业之前一直想着做C++的,后来因为各种原因(跟学校导师相关),走向了.NET之路,从而时不时补一下.net的基础知识,因为自己的.NET知识还不是很扎实.近期每天早 ...

  5. Docker入门

    -----------------------------------------Docker入门教程(一)介绍Docker入门教程(二)命令Docker入门教程(三)DockerFileDocker ...

  6. iphone 与 ipad -- UIPopoverPresentationViewController

    iOS8.0之后, 苹果推出了UIPopoverPresentationViewController, 在弹出控制器时, 统一采用 presentViewController, 但是要实现iPhone ...

  7. [原博客] POJ 2505 A multiplication game 组合游戏

    题目链接题意: 有一个数p=1,甲乙两人轮流操作,每次可以把p乘2~9中的一个数,给定一个n,当一个人操作后p>=n,那么这个人赢,问先手是否必胜. 必胜状态:存在一种走法走到一个必败状态. 必 ...

  8. 李洪强漫谈iOS开发[C语言-028]-sizeof运算符

  9. 最全的微软msdn原版windows系统镜像和office下载地址集锦

    随着windows的发展,越来越多的人都热衷于微软的原版系统下载了,相比之前的版本比如winxp版本,windows vista/win7/win8/win8.1/win10后来的版本在安装方面也比较 ...

  10. C++ Socket TCP "Hello World!"

    这是C++ SOCKET网络程序中的C/S结构之TCP "Hello World !",共两个控制台工程: //////////////////////////////////// ...