HDU 5392 BC #51

就是求最大公倍数,但要用分解质因子求。

自己写的WA到爆。。。。

#include<iostream>
#include<stdio.h>
#include<math.h>

#include<algorithm>

using namespace std;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define ll long long int

#define maxn 3000005
#define maxm 500010
int t,n;
int f[maxn],v[maxn],num[maxn];
int maxx(int a,int b){
    return a>b?a:b;
}
int main()
{
    rd(t);
    long long mod=3221225473;
    while(t--){
        rd(n);
        for(int i=1;i<=n;i++)
        {
            rd(f[i]);
            v[i]=0;
            num[i]=0;
        }
        for(int i=1;i<=n;i++)
        {
            if(!v[i]){
                int l=0;
                int k=i;
                while(!v[k]){
                    l++;
                    v[k]=1;
                    k=f[k];
                }//求循环节长度
                for(int j=2;j*j<=l;j++)//质因子分解
                {
                    int nn=0;
                    while(l%j==0) {nn++;l/=j;}
                    num[j]=maxx(num[j],nn);
                }
                if(l>1) num[l]=maxx(1,num[l]);
            }
        }
        ll res=1;
        for(int i=2;i<=n;i++)
        {
            while(num[i]--) res=(res*i)%mod;
        }
        printf("%I64d\n",res);
    }
    return 0;
}

  

时间: 2024-10-11 18:14:26

HDU 5392 BC #51的相关文章

hdu 5234 (bc #42 C)Happy birthday(dp)

Happy birthday Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 672    Accepted Submission(s): 302 Problem Description Today is Gorwin’s birthday. So her mother want to realize her a wish. Gorwin

hdu 5365 (bc #50 1002 )Run

Run Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 594    Accepted Submission(s): 265 Problem Description AFA is a girl who like runing.Today,he download an app about runing .The app can record

hdu 5392 Infoplane in Tina Town (质因子分解求gcd)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5392 题意:至今没弄懂题意.按admin的意思猜的:求出每个循环的长度,然后求出这些长度的最小公倍数.结果%3221225473. 分析:首先求出每个循环的长度len,由于结果很大,用gcd求最小公倍数的时候不能直接模3221225473(模下gcd是不正确的......),可以将所有的长度len分解质因子,记录每种质因子的最大数量,,最后快速幂求结果. 代码: #include <iostream>

hdu 5392 Infoplane in Tina Town(数学)

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. als

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 Problem Description There is a big stone with smooth surface in Tina Town. When peop

hdu 5364 (bc#50 1001) Distribution money

Distribution money Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 276    Accepted Submission(s): 163 Problem Description AFA want to distribution her money to somebody.She divide her money into

hdu 5366 (bc #50 1003) The mook jong

The mook jong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 269    Accepted Submission(s): 205 Problem Description ![](../../data/images/C613-1001-1.jpg) ZJiaQ want to become a strong man, so

hdu 5392 Zball in Tina Town(素数)

题意:求(x-1)!modx(x<10^9),哥德巴赫猜想,打表得当x为素数时,结果为x-1,合数时为0:x=4时为2特判: 思路:判断素数的时候脑子抽了,想成素数大数了,然后一直TLE; 当要判断的数的平方根为10^8级别时再考虑大数情况... #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t,n,m; int main(){ int i,j,k,f

hdu 5203 &amp;&amp; BC Round #37 1002

代码参考自:xyz111 题意: 众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:勇太有一根长度为n的木棍,这个木棍是由n个长度为1的小木棍拼接而成,当然由于时间放置的久了,一些小木棍已经不牢固了,所以勇太想让六花把这个木棍分成正整数长度的4段,其中有3段要没有不牢固的小木棍,勇太希望这3段木棍的长度和可以最大.同时六花希望在满足勇太要求的情况下让这三根木棍能拼成一个三角形,请问萌萌哒六花有多少种可行的分割方案呢?当然,这个问题对于萌萌哒六花来说实在是太难了