hdu 5392
3
1 3 2
6
2 3 4 5 6 1
6
题意:给一个转置求它的循环长度
题解:分解成循环求最小公倍数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 3221225473
#define N 100005
#define MIN 0
#define MAX 1000001 const int maxn = 3000005;
int a[maxn],vis[maxn],sum[maxn]; void fin(int num)
{
int tt;
for(int i = 2; i <= num; i++)
{
tt = 0;
while(num%i == 0)
{
num/=i;
tt++;
}
if(tt > sum[i])
sum[i] = tt;
}
} ll pow_mod(ll q,int n,ull mod)
{
if(n == 0)
return 1;
ll x = pow_mod(q,n/2,mod);
ll ans = (ll)x*x%mod;
if(n %2 == 1)
ans = ans *q % mod;
return ans;
} int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ll ans;
for(int i = 1; i <= n; i++)
scanf("%d",&a[i]);
memset(vis,0,sizeof(vis));
memset(sum,0,sizeof(sum));
for(int i = 1; i <= n; i++)
{
if(vis[i])
continue;
int tmp = i;
int num = 0;
while(!vis[tmp])
{
vis[tmp] = 1;
tmp = a[tmp];
num ++;
}
//printf("num:%d\n",num);
fin(num);
} ans = 1;
for(int i = 2; i <= n; i++)
if(sum[i])
{
//printf("%d\n",sum[i]);
ans = (ans * pow_mod(i,sum[i],(ll)MOD))%MOD;
}
printf("%I64d\n",ans);
}
return 0;
}
hdu 5392的更多相关文章
- hdu 5392 Infoplane in Tina Town(数学)
Problem Description There is a big stone with smooth surface in Tina Town. When people go towards it ...
- HDU 5392 BC #51
就是求最大公倍数,但要用分解质因子求. 自己写的WA到爆.... #include<iostream> #include<stdio.h> #include<math.h ...
- HDU 5392 Infoplane in Tina Town
Infoplane in Tina Town Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 524288/524288 K (Jav ...
- hdoj 5392 Infoplane in Tina Town
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 展示博客(Beta版本)
团队:xjbz 1. 团队成员博客,源码仓库地址. coding:https://git.coding.net/z404395979/xjbz.git 钟平辉(071):http://www.cnbl ...
- JAVA委托事件处理机制
1)事件:用户对程序的某一种功能性操作. Java中的事件主要有两种: 1.组件类事件 componentEvent.ContainerEvent.WindowEvent.FocusEvent.Pai ...
- continue和break的特殊用法。
break在程序中一般来说的作用就是跳出当前循环,然后再据需执行循环外的语句.continue也是对当前循环来说直接进入到下一次循环.其实我们在程序中有时候循环体嵌套太多,进行到某一步是希望直接bre ...
- caffe实现GAN
我实现GAN网络结构比较复杂: 通过建立两个一模一样的网络,他们相对应的层共享权重,一个网络用来跟新D model另一个网络用来更新G model 更新G model的网络,D部分只进行梯度传递,不进 ...
- 《javascript设计模式与开发实践》阅读笔记(10)—— 组合模式
组合模式:一些子对象组成一个父对象,子对象本身也可能是由一些孙对象组成. 有点类似树形结构的意思,这里举一个包含命令模式的例子 var list=function(){ //创建接口对象的函数 ret ...
- STL之queue
描述 使用STL中的queue,完成入队.出队.获取队首.获取队尾等基本操作. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { queue<int> ...
- 将Python程序打包为exe方法
将Python程序打包为exe文件,需要使用到的工具是pyinstaller pyinstaller是一个多平台的Python程序打包为exe的免费工具 安装pyinstaller: 1,在Windo ...
- Code::Blocks出现64-Bit mode not compled in解决方法
原因是:Settings->compilter你选了Target x86 _64(64bit),选择Target x86 _32(32bit)即可 废了老半天劲才找到原因,希望能让朋友们少走弯路
- Mego开发文档 - 索引
Mego 开发文档 Mego 快速概述 主要特性 获取Mego 使用流程 模型 查询 保存数据 入门 Mego 快速开始 创建项目 安装Nuget包 创建连接字符串 创建模型及数据上下文(添加引用) ...
- Mac 中配置Apache
使用的mac版本是10.10.1,mac自带的Apache环境 分为两部分: 1.启动Apache 2.设置虚拟主机 启动Apache 打开终端, >>sudo apachectl -v, ...