Problem Description
There is a big stone with smooth surface in Tina Town. When people go towards it, the stone surface will be lighted and show its usage. This stone was a legacy and also the center of Tina Town’s calculation and control system. also, it can display events in Tina Town and contents that pedestrians are interested in, and it can be used as public computer. It makes people’s life more convenient (especially for who forget to take a device).
Tina and Town were playing a game on this stone. First, a permutation of numbers from 1 to n were displayed on the stone. Town exchanged some numbers randomly and Town recorded this process by macros. Town asked Tine,”Do you know how many times it need to turn these numbers into the original permutation by executing this macro? Tina didn’t know the answer so she asked you to find out the answer for her.
Since the answer may be very large, you only need to output the answer modulo 3∗230+1=3221225473 (a prime).
 
Input
The first line is an integer T representing the number of test cases. T≤5
For each test case, the first line is an integer n representing the length of permutation. n≤3∗106
The second line contains n integers representing a permutation A1...An. It is guaranteed that numbers are different each other and all Ai satisfies ( 1≤Ai≤n ).
 
Output
For each test case, print a number ans representing the answer.
 
Sample Input
2
3
1 3 2
6
2 3 4 5 6 1
 
Sample Output
2
6
 

中文题目:

Tina Town 的镇中有一块表面平整光滑的大石头, 当人面向它走进时, 石头的表面就会亮起, 显示出它的用途. 这块石头是前人留下来的东西,是Tina Town算力和控制系统的核心, 同时它也可以显示Tina Town的大小事和行人关注的内容,也可以作为公共的计算机使用 ,极大地方便了人们的生活(特别是上街忘带终端的人们啦).

Tina和Town在这块大石头上玩一个游戏. 石头上首先显示出了1到n排列的n个数,Town则随机交换了一些数, 然后Town通过宏将这个交换的过程记录下来了. Town 问 Tina: 你知道执行几次这个宏, 这些数会恢复最早的排列嘛? Tina是一个蠢蠢的女孩子, 当然不知道啦, 于是她想向你请教呢.

来自官方题解:

给出一个置换,求它的循环长度。数据范围 3\times 10^63×10​6​​。

其实没有什么好说的,就分解成循环求长度的最小公倍数就好了。对于这个模数要用unsigned int存,这个最小公倍数的求法不能用欧几里得,直接每次分解质因数,用线性筛预处理一下就好了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<stdlib.h>
using namespace std;
#define ll long long
#define N 3000006
#define MOD 3221225473
int n;
int a[N];
int vis[N];
int cou[N];
inline int sca() //输入外挂
{
int res=,ch,flag=;
if((ch=getchar())=='-')
flag=;
else if(ch>=''&&ch<='')
res=ch-'';
while((ch=getchar())>=''&&ch<='')
res=res*+ch-'';
return flag?-res:res;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
a[i]=sca();
vis[i]=;
cou[i]=;
} for(int i=;i<=n;i++)
{
if(vis[i]) continue;
int len=;
int k=a[i];//k用来查找长度
while(k!=i)//如果当前的数与原来的位置不一样,则长度加1
{
len++;
vis[k]=;
k=a[k];
}
for(int j=;j*j<=len;j++)//这边用来计算最小公倍数,不能用lcm,因为这里是单个数
{
int c=;
if(len%j==)//如果可以分解质因数的话,则连续分解
{
while(len%j==)
{
c++;
len=len/j;
}
cou[j]=max(cou[j],c);//记录这个质因数的个数
}
}
if(len>) cou[len]=max(cou[len],);//记住这里要加上,比如说10来分解质因数,最后剩下5(10/2=5),则cou【5】也要算进去
} ll ans=;
for(int i=;i<=n;i++)//这边计算最小公倍数
{
for(int j=;j<cou[i];j++)
ans=ans*i%MOD;
}
printf("%I64d\n",ans);
}
return ;
}
 
3*2^{30}+1=32212254733∗2​30​​+1=3221225473(一个素数)的模就行了.

hdu 5392 Infoplane in Tina Town(数学)的更多相关文章

  1. HDU 5392 Infoplane in Tina Town

    Infoplane in Tina Town Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 524288/524288 K (Jav ...

  2. hdoj 5392 Infoplane in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...

  3. hdu5392 Infoplane in Tina Town(LCM)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Infoplane in Tina Town Time Limit: 14000/ ...

  4. hdu 5391 Zball in Tina Town 威尔逊定理 数学

    Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

  5. HDU 5391Z ball in Tina Town 数论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc:  http://bestcoder.hdu.edu.cn/contests/c ...

  6. hdu 5391 Zball in Tina Town(打表找规律)

    问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...

  7. HDU 5391 Zball in Tina Town【威尔逊定理】

    <题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...

  8. HDU.5394.Trie in Tina Town(回文树)

    题目链接 \(Description\) 给定一棵\(Trie\).求\(Trie\)上所有回文串 长度乘以出现次数 的和.这里的回文串只能是从上到下的一条链. 节点数\(n\leq 2\times ...

  9. HDU 5391 Zball in Tina Town (打表,水)

    题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...

随机推荐

  1. ionic框架前端生产环境的简单部署

    1. 效果对比 1.1 开发环境 css+js+lib文件大小为好多M :) 1.2 部署环境(生产环境) css+js+lib文件大小约为800K 文件大小:好多M–>800K(多少自己试下) ...

  2. windows服务程序

    首先创建一个myService的窗体程序作为服务安装卸载控制器(管理员身份运行vs,windows服务的安装卸载需要管理员权限)   在同一个解决方案里面添加一个windows服务程序,取名myWin ...

  3. 6.关于QT中的内存管理,动态的制作,动态库的调用,静态库的制作

     一  QT的内存管理 1  QT中的内存管理是QObject来管理的 2  QT中的内存管理没有cocos2dx中的引用计数 3  组件能够指定父对象 QTimer *timer = QTime ...

  4. IIS无法启动问题的解决

    IIS无法启动,显示“服务并未即使响应启动或控制请求”,我用两种办法都没有解决:1.把IIS卸载重装也不行:2.到服务中world wide web publishing服务也不能启动,提示127错误 ...

  5. SQLite中不支持的sql语法

    今天很自然的在写Sql语句的时候用了Top,一开始没发现问题,因为我从数据库读出的值正好是0,而我习惯变量定义的时候也都赋值0,可是到我不要0的时候我就发现问题了.后来才知道,可爱的小sqlite竟然 ...

  6. Java基础知识强化32:String类之String类的判断功能

    1. String类的判断功能: boolean equals (Object obj ) boolean equalsIgnoreCase (String str ) boolean contain ...

  7. hdu 1076

    水题 AC代码: #include <iostream> using namespace std; int main() { int i,k,t,y,n; cin>>t; wh ...

  8. 在div+css中用到的js代码注意return

    今天做了一个项目,美工做好后放在了form中(没有加runat=server),由于用到了服务器控件,所以这里要加,否则报错,关键一段div代码是: <form id="form_re ...

  9. Android-应用的本地化及知识拓展之配置修饰符

    步骤很简单,只需要两步: 1.创建带有目标语言的配置修饰符的资源子目录 2.将可选资源放入该目录下,android系统会自动处理后续工作 在这里我们需要讲解一下配置修饰符. 中文的配置修饰符:-zh, ...

  10. android sax解析xml 文件 动态加载标题

    要解决一个问题 : 问题描述为 把标题动态的加载到 listView子布局中 我们首先通过 java程序写一个把标题写到xml文件的程序.这个程序会在以后讲解. 现在截图 已经写好的xm文件格式如下 ...