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. 用javascript操作xml(三)关于Jquery的html()不兼容IE的解决办法

    当 $("#xxx").html(data); 不兼容,方法替换为 document.getElementById("xxx").innerHTML=data;

  2. yii2 gii页面404和debug调试栏无法显示解决方法

    在debug和gii配置项中加一项: 'allowedIPs' => ['127.0.0.1', '::1', '*.*.*.*']即可 注:因为yii默认只让127.0.0.1访问

  3. 给destoon商城的列表中和首页添加购物车功能

    如何给destoon商城的列表中和首页添加购物车功能? 目前加入购物车的功能只存在商城的详细页面里,有时候我们需要批量购买的时候,希望在列表页就能够使用这个加入购物车的功能. 修改步骤见下: 例如在商 ...

  4. Python 学习之urllib模块---用于发送网络请求,获取数据(5)

    查询城市天气最后一节 需要导入上一节的结果city10.py #!/usr/bin/python# -*- coding: UTF-8 -*-import urllib.requestfrom  ci ...

  5. 树莓派上搭建基于Python+web.py+fastcgi+lighttpd的网站

    最近在网上淘了一个树莓派,什么是树莓派?这里是他的官方网站你可以去看看. 简单的说就是一块使用了ARM11的CPU,具有256MB或512MB内存的具有两个USB接口,一个RJ45接口,HDMI输出和 ...

  6. combo下拉列表选择

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. check、continue、exit的区别

    DATA:BEGIN OF lt_table OCCURS 0,      i_row   TYPE i,      i_col   TYPE i,     END OF lt_table. lt_t ...

  8. 玩转createjs

    标题党"玩转", 真的是在玩怎么转... 参考一篇很经典的博文:createjs入门 做移动版(750x1334)的时候出来不居中啊, 不是掉在下面就是滑到右面, canvas里面 ...

  9. 不重复查询mysql

    select EquipmentSID,MIN(MatureTime),MIN(ISlock) from table group by name String sql =” Select * from ...

  10. 消息队列feed程序实现中的问题

    因项目需要, 构建了很多消息队列还排队处理任务, 相应的每个队列也配有一个feed程序来feed消息 一开始很简单地这样做: while (true){ $msg = $query->bPop( ...