hdu 5392 Infoplane in Tina Town(数学)
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).
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 ).
3
1 3 2
6
2 3 4 5 6 1
6
中文题目:
Tina Town 的镇中有一块表面平整光滑的大石头, 当人面向它走进时, 石头的表面就会亮起, 显示出它的用途. 这块石头是前人留下来的东西,是Tina Town算力和控制系统的核心, 同时它也可以显示Tina Town的大小事和行人关注的内容,也可以作为公共的计算机使用 ,极大地方便了人们的生活(特别是上街忘带终端的人们啦). Tina和Town在这块大石头上玩一个游戏. 石头上首先显示出了1到n排列的n个数,Town则随机交换了一些数, 然后Town通过宏将这个交换的过程记录下来了. Town 问 Tina: 你知道执行几次这个宏, 这些数会恢复最早的排列嘛? Tina是一个蠢蠢的女孩子, 当然不知道啦, 于是她想向你请教呢.
来自官方题解:
给出一个置换,求它的循环长度。数据范围 3\times 10^63×106。
其实没有什么好说的,就分解成循环求长度的最小公倍数就好了。对于这个模数要用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∗230+1=3221225473(一个素数)的模就行了.
hdu 5392 Infoplane in Tina Town(数学)的更多相关文章
- 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> ...
- hdu5392 Infoplane in Tina Town(LCM)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Infoplane in Tina Town Time Limit: 14000/ ...
- hdu 5391 Zball in Tina Town 威尔逊定理 数学
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- HDU 5391Z ball in Tina Town 数论
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc: http://bestcoder.hdu.edu.cn/contests/c ...
- hdu 5391 Zball in Tina Town(打表找规律)
问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...
- HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...
- HDU.5394.Trie in Tina Town(回文树)
题目链接 \(Description\) 给定一棵\(Trie\).求\(Trie\)上所有回文串 长度乘以出现次数 的和.这里的回文串只能是从上到下的一条链. 节点数\(n\leq 2\times ...
- HDU 5391 Zball in Tina Town (打表,水)
题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...
随机推荐
- js判断上传文件大小
下面提供三款网页特效判断上传文件大小哦,这三种方法是现在限制文件上传大小比较好的方法,可以在客户上传文件时限制上传文件大小判断处理<!doctype html public "-//w ...
- C#委托与事件之观察者Observer设计模式
前言 委托: 委托是一种在对象里保存方法引用的类型,同时也是一种类型安全的函数指针. 或委托可以看成一种表示函数的数据类型,类似函数指针. 事件是特殊的委托 观察者模式:两种角色:(1)Subj ...
- onActivityResult不执行 或者 onActivityResult的解决方法
开发人员都知道,可以通过使用 startActivityForResult() 和 onActivityResult() 方法来传递或接收参数.然而在一次使用中,还没等到被调用的 Activity 返 ...
- ViutualBox虚拟机里添加磁盘
1.首先在VirtualBox界面给虚拟机添加一块磁盘 2. 启动系统,查看当前磁盘空间 Last login: Tue Mar 15 22:24:47 2016 from 192.168.1.100 ...
- nginx安装(正式)
一.安装说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64软件:nginx-1.10.1.tar.gz其他所 ...
- 使用VS Code调试TypeScript游戏程序JsTankGame成功!!!
TypeScript游戏程序JsTankGame不是本人写的,是从CSDN下载的. JsTankGame是用Visual Studio开发的,因此在Visual Studio下调试非常顺畅.本人尝试用 ...
- 关于winform主题IrisSkin2的编写
第一步:首先引用IrisSkin2.dll. 第二步自定义类: /// <summary> /// 窗体主题边界类 /// </summary> public class Fo ...
- 第1章 网络编程基础(4)——TCP/IP通信
TCP协议利用网络层IP协议提供不可靠的通信服务,解决分组的重传和排序问题,为应用程序提供可靠的.端到端的.面向连接的基于字节流的服务. 对等TCP传输实体间的通信具有如下特征: 全双工 只支持两个端 ...
- 【转】C++:MessageBox的常见用法
一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口 ...
- WIN8 WIN10系统如何完全获取用户管理员权限
按住WIN+R 2 计算机配置----Windows设置----安全设置----本地策略----安全选项----用户账户控制:以管理员批准模式运行所有管理员,把启用改为禁止然后重启电脑