Color
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的更多相关文章
- 【转】c#、wpf 字符串,color,brush之间的转换
转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...
- Python为8bit深度图像应用color map
图片中存在着色版的概念,二维矩阵的每个元素的值指定了一种颜色,因此可以显示出彩色. 迁移调色板 下述python代码将VOC数据集中的某个语义分割的图片的调色板直接应用在一个二维矩阵代表的图像上 #l ...
- (转)System.Drawing.Color的颜色对照表
经常使用System.Drawing.Color, 本篇介绍一下颜色与名称及RGB值的对应关系. 1. 颜色与名称的对照表(点击下图放大看): 2. 颜色与RGB值对照表: Color.AliceBl ...
- 激光打印机的Color/paper, Xerography介绍
Color Basic 看见色彩三要素: 光源,物体,视觉 加色色彩模型:R,G,B 多用于显示器 减色色彩模型:C,M,Y,K 多用于打印复印 Paper 东亚地区常用A系列标准用纸,在多功能一体机 ...
- 安卓工具箱:color of Style
<?xml version="1.0" encoding="utf-8"?> <resources> <color name=&q ...
- UITableView 一直显示滚动条(ScrollBar Indicators)、滚动条Width(宽度)、滚动条Color(颜色)
在 IOS 中,对 UIScrollView 的滚动条(ScrollBar Indicators)的自定义设置接口,一直都是很少的.除了能自定义简单的样式(UIScrollViewIndicatorS ...
- OpenCASCADE Color Scale
OpenCASCADE Color Scale eryar@163.com Abstract. The color scale is a specialized label object that d ...
- Color Transfer between Images code实现
上计算机视觉课老师布置的作业实现论文:Color Transfer between Images 基本思路是: 1.给定srcImg和targetImg 2.将RGB空间转为Lab空间 3.根据论文中 ...
- ZOJ Problem Set - 1067 Color Me Less
这道题目很简单,考察的就是结构体数组的应用,直接贴代码了 #include <stdio.h> #include <math.h> typedef struct color { ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
随机推荐
- c++与C# winform的消息通讯--(结构体与byte数组的使用)
近期正在做一个蓝牙驱动的使用程序,其中有一块从c++发送数据到C#的部分,网上查了很多资料,大多都是介绍如何通过调用函数获取用户数据.并且在消息发送中,很少介绍如何发送一个结构体,并且结构体里面有 b ...
- firefox下对ajax的onreadystatechange的支持情况分析及解决
一.问题: var xmlHttp; function savecarttodata(){ createXMLHttpRequest(); var rndcode = new Date().getTi ...
- jquery禁用a标签,jquery禁用按钮click点击
jquery禁用a标签方法1 $(document).ready(function () { $("a").each(function () { var textValue = $ ...
- Groovy 数组操作
将字符串转为map def str="['汤菜':['1000000028','1000000030'],'肉菜':['1000000032'],'素材':['1000000031']]&q ...
- OC修饰词 - 内存管理
<招聘一个靠谱的 iOS>—参考答案(上) 说明:面试题来源是微博@我就叫Sunny怎么了的这篇博文:<招聘一个靠谱的 iOS>,其中共55题,除第一题为纠错题外,其他54道均 ...
- 支持HTML5 SqlLite的AndroidApp
简介: 想要建立一个支持HTML5的Android App; 这个HTML5的程序需要使用本地存储,特别是sqllite; 用eclipse创建了一个app,这个app默认在res/layout建了两 ...
- TCP/IP入门学习(1)---分层概述
本文旨在记述一些学习中的笔记 OSI分层:应用层,表示层,会话层,传输层,网络层,数据链路层,物理层 详细点: 1.应用层:为应用程序提供服务并规定程序中通信相关细节. 2.表示层:将应用处理的信息转 ...
- win7 安装SQL Server 2005 开发版 图文教程
转自win7 安装SQL Server 2005 开发版 图文教程 ----------------------------写在安装前------------------------------ 一. ...
- Android sqlite 数据库在java代码中的增删改查
private void queryPerson(PersonSQLiteOpenHelper personSQLiteOpenHelper) { SQLiteDatabase sqLiteDatab ...
- nc 命令汇总
转自: http://blog.chinaunix.net/uid-20068039-id-359170.html 1.远程拷贝文件从server1拷贝文件到server2上.需要先在server2上 ...