HDU 5392 Infoplane in Tina Town
Infoplane in Tina Town
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 805 Accepted Submission(s): 168
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).
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
).
ans
representing the answer.
2
3
1 3 2
6
2 3 4 5 6 1
2
6
pid=5394" target="_blank">5394
5393pid=5390" target="_blank">5390
5389给出一个序列,求变换几次能够回到原来的位置。比方 1 3 2 ,3 不在原来的位置,变到3位置。次数加1,2变到2,次数+1.得到2.。
做法就是分解循环长度。然后求下最小公倍数。
可是不能直接用lcm求最小公倍数。
。我们能够考虑用质数分解来求,即公共的质因子乘每一个数本身的质因子。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull;
int a[3000010];
int vis[3000010];
int b[3000010];
const ll mod=3221225473;
inline int read()
{
char ch;
for (ch=getchar(); ch<48||ch>57;) ch=getchar();
int d=0;
for (; ch>47&&ch<58; ch=getchar()) d=d*10+ch-48;
return d;
}
ll gcd(ll a,ll b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1; i<=n; i++)
a[i]=read();
memset(vis,0,sizeof(vis));
memset(b,0,sizeof(b));
for(i=1; i<=n; i++)
{
if(!vis[i])
{ int t=i;
int s=0;
while(!vis[t])
{
s++;
vis[t]=1;
t=a[t];
}
for(j=2; j*j<=s; j++)
{
int cnt=0;
while(s%j==0)
{
cnt++;
s/=j;
}
b[j]=max(b[j],cnt); //统计公共的质因子。 }
if(s>1)
b[s]=max(b[s],1);
}
}
// cout<<lcm(121,11)<<endl;
ull ans=1;
for(i=2; i<=n; i++)
for(j=1; j<=b[i]; j++)
ans=ull(ans)*i%mod;
cout<<ans<<endl;
}
}
HDU 5392 Infoplane in Tina Town的更多相关文章
- hdu 5392 Infoplane in Tina Town(数学)
Problem Description There is a big stone with smooth surface in Tina Town. When people go towards it ...
- 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 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 5391 Zball in Tina Town 威尔逊定理 数学
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- 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 ...
随机推荐
- 【Codeforces1117C_CF1117C】Magic Ship(构造)
题目: Codeforces1117C 考的时候很困,开局半小时后才过A,只做出来AB,排名3000+,掉了119--半夜体验极差. 翻译: 你是一个船长.最初你在点 \((x_1,y_1)\) (显 ...
- 微信接口本地调试(IIS服务器)
1.下载ngrok,并注册获得token.官网下载地址:https://ngrok.com/ 如果你是在官网下载的,到后面映射域名的时候会要求购买他们的服务. 这里我们用一个国内免费的ngrok服务器 ...
- maven 纯注解一步一步搭建Spring Mvc项目(入门)
初次接触spring MVC项目,通过一段时间的学习,本文介绍一种以纯注解的方法去配置spring MVC环境,让那些配置的.xml文件统统见鬼吧. 什么是Spring MVC Spring MVC属 ...
- 话说:Hibernate二级缓存
Hibernate缓存分类: 一.Session缓存(又称作事务缓存):Hibernate内置的,不能卸除. 缓存范围:缓存只能被当前Session对象访问.缓存的生命周期依赖于Session的生命周 ...
- linux设置库文件加载包含路径
第一种方式vim /etc/ld.so.conf 将要包含的路径添加到此文件中退出重新登录使配置生效或者执行命令source /etc/ld.so.conf 另一种方式利用LIBRARY_PATH和L ...
- Android RecyclerView利用Glide加载大量图片into(Target)导致OOM异常
学过android的人应该都知道Glide是一个无比强大的图片加载库,它内部已经提供了很好的缓存机制供我们选择,我们只需一个参数调用即可(DiskCacheStrategy()),而不必像Univer ...
- 利用js写全选操作
<script type="text/javascript"> function checkall(qx) { var ck=document.getElementsB ...
- PHP第二阶段学习 一、php的基本语法
php的基本语法 输出语句:a. echo输出:可以输出多个字符串,逗号隔开 b. print输出:只能输出一个字符串,返回true或false c. print_r():可以把字符串和数字简单 ...
- Java 基础入门随笔(2) JavaSE版——关键字、进制转换、类型转换
1.Java语言-关键字 关键字:被java语言赋予了特殊含义的词,特点是所有的字母都为小写. java涉及到的关键字整理: 用于定义数据类型的关键字 class interface byte sho ...
- Tomcat服务器安装与第一个jsp网页程序
1.安装tomcat服务器之前需要,先安装相应版本的jdk,个人理解Tomcat的大部分功能是使用了java的 jdk jar包的. jdk包下载方式网上可以查到 下载完后可以解压到一个指定目录,并在 ...