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 ...
随机推荐
- RxSwift:ReactiveX for Swift 翻译
RxSwift:ReactiveX for Swift 翻译 字数1787 阅读269 评论3 喜欢3 图片发自简书App RxSwift | |-LICENSE.md |-README.md |-R ...
- UWP 页面间传递参数(常见类型string、int以及自定义类型)
这是一篇很基础的,大佬就不要看了,也不要喷,谢谢
- java8-Stream之数值流
在Stream里元素都是对象,那么,当我们操作一个数字流的时候就不得不考虑一个问题,拆箱和装箱.虽然自动拆箱不需要我们处理,但依旧有隐含的成本在里面.Java8引入了3个原始类型特化流接口来解决这个问 ...
- 使用静态基类方案让 ASP.NET Core 实现遵循 HATEOAS Restful Web API
Hypermedia As The Engine Of Application State (HATEOAS) HATEOAS(Hypermedia as the engine of applicat ...
- 算法题丨3Sum
描述 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all ...
- hadoop2.6.0实践:002 检查伪分布式环境搭建
1.检查网络配置[root@hadoop-master ~]# cat /etc/sysconfig/networkNETWORKING=yesHOSTNAME=hadoop-masterGATEWA ...
- api-gateway实践(01)服务网关 - 原型功能
一.服务注册 1.增加组:LsqGrpA 2.增加版本:LsqVerA 3.增加api:LsqApiA 3.1.基本信息 3.2.前端定义 3.3.后端定义 二.服务上线和服务授权 1.服务上线 2. ...
- linux下mongodb安装、服务器、客户端、备份、账户命令
在linux环境安装mongoDB: 一般认为偶数版本为稳定版 如 1.6.x,奇数版本为开发版如1.7.x 32bit的mongoDB最大能存放2g的数据,64bit没有限制 方法1: 终端执行: ...
- Hibernate(三): org.hibernate.HibernateException: No CurrentSessionContext configured!
Hibernate版本5.2.9 获取Session的方式是sessionFactory.getCurrentSession(); 比较老一些的版本使用的是sessionFactory.openSes ...
- POJ-1251 Jungle Roads---MST裸题(需要编号)
题目链接: https://vjudge.net/problem/POJ-1251 题目大意: 首先给你一个图,需要你求出最小生成树,输入N个节点,用大写字母表示了节点,然后节点与节点之间有权值. 思 ...