日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Orac and LCM #641(div2) c题--求质因数次小指数

發布時間:2023/12/3 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Orac and LCM #641(div2) c题--求质因数次小指数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Orac and LCM cf地址

For the multiset of positive integers s={s1,s2,…,sk}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:

gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.

lcm(s) is the minimum positive integer x, that divisible on all integers from s.
For example, gcd({8,12})=4,gcd({12,18,6})=6 and lcm({4,6})=12. Note that for any positive integer x, gcd({x})=lcm({x})=x.

Orac has a sequence a with length n. He come up with the multiset t={lcm({ai,aj}) | i<j}, and asked you to find the value of gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence.

Input
The first line contains one integer n (2≤n≤100000).

The second line contains n integers, a1,a2,…,an (1≤ai≤200000).

Output
Print one integer: gcd({lcm({ai,aj}) | i<j}).

Examples
inputCopy
2
1 1
outputCopy
1
inputCopy
4
10 24 40 80
outputCopy
40
inputCopy
10
540 648 810 648 720 540 594 864 972 648
outputCopy
54
Note
For the first example, t={lcm({1,1})}={1}, so gcd(t)=1.

For the second example, t={120,40,80,120,240,80}, and it’s not hard to see that gcd(t)=40.

題目大意: 兩兩求最小公倍數,然后得到集合,求最大公因數。

思路: 求質因數次小的指數。
注意:當有某個質因數的個數為n的的時候,應該any*=次小指數
當為n-1的時候 應該為any*=最小指數。

直接把0算進去應該不用考慮這兩種情況了

我的代碼:

#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <stack> #include <vector> #include <set> #include <map> #include <bitset> #define INF 0x3f3f3f3f3f3f3f3f #define FILL(a,b) (memset(a,b,sizeof(a))) #define re register #define lson rt<<1 #define rson rt<<1|1 #define lowbit(a) ((a)&-(a)) #define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0); #define fi first #define rep(i,n) for(int i=0;(i)<(n);i++) #define rep1(i,n) for(int i=1;(i)<=(n);i++) #define se secondusing namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int > pii; const ll mod=104857601; const int N =2e5+10; const double eps = 1e-6; const double pi=acos(-1); int gcd(int a,int b){return !b?a:gcd(b,a%b);} int dx[4]={-1,0,1,0} , dy[4] = {0,1,0,-1}; int a[N]; int p[N], cnt; bool st[N];void get_primes(int n) {for (int i = 2; i <= n; i ++ ){if (!st[i]) p[cnt ++ ] = i;for (ll j = 0; p[j] <= n / i; j ++ ){st[p[j] * i] = true;if (i % p[j] == 0) break;}} }int pow1(int a,int b) {ll any=1;while(b){if(b&1) any*=a;a*=a;b>>=1;}return any; }int d1[N]; int d2[N]; int d3[N]; int main() {get_primes(N);int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}if(n==2){ printf("%lld",ll(a[1]/gcd(a[1],a[2]))*a[2]);return 0;}for(int i=1;i<=n;i++){for(int j=0;j<cnt;j++){if(a[i]<p[j]||a[i]<p[j]*p[j]) break;if(a[i]%p[j]==0){int x=0;d3[p[j]]++;while(a[i]%p[j]==0){a[i]/=p[j];x++;}if(x<=d1[p[j]]||d1[p[j]]==0){d2[p[j]]=d1[p[j]];d1[p[j]]=x;}else if(x<d2[p[j]]||d2[p[j]]==0){d2[p[j]]=x;}}}if(a[i]>1){d3[a[i]]++;int x=1;if(x<=d1[a[i]]||d1[a[i]]==0){d2[a[i]]=d1[a[i]];d1[a[i]]=x;}else if(x<d2[a[i]]||d2[a[i]]==0){d2[a[i]]=x;}}}ll any=1;for(int i=0;i<200000;i++){if(d3[i]==n) any*=pow1(i,d2[i]);else if(d3[i]==n-1) any*=pow1(i,d1[i]);}printf("%lld\n",any);return 0; }

大神代碼:優美的求次小指數,在最小指數的基礎上求。

#include <bits/stdc++.h>using namespace std;typedef long long ll;ll n,d[100007],a,b;int main() {cin>>n;cin>>d[1]>>d[2];a=__gcd(d[1],d[2]);b=d[1]*d[2];for(int i=3;i<=n;i++){cin>>d[i];b=__gcd(a*d[i],b);a=__gcd(a,d[i]);}cout<<b/a;return 0; }

總結

以上是生活随笔為你收集整理的Orac and LCM #641(div2) c题--求质因数次小指数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美一级大片 | 成年人在线观看视频 | 国语对白真实视频播放 | 伊人影院在线视频 | 国产精品久久久久久 | 亚洲欧美综合视频 | 在线免费一区 | 秋霞在线观看秋 | 免费一级淫片 | 无码黑人精品一区二区 | 日本视频三区 | 国产成人在线视频播放 | 成人黄色在线播放 | 成人国产免费视频 | 狠狠干天天射 | 亚洲v日韩v综合v精品v | 四虎影院成人 | 欧美性受xxxxx | 国产精品zjzjzj在线观看 | 亚洲精品a| 日本免费成人 | 福利国产在线 | 亚洲一区二区网站 | 久久嗨| 亚洲女人毛茸茸 | 中文字幕五码 | 欧美v日韩 | 另类视频一区 | 国产性猛交xxxⅹ交酡全过程 | 国产成人激情视频 | 在线观看免费黄视频 | 国产精品theporn | 亚洲女人久久久 | 深夜福利网站 | 欧美性大战xxxxx久久久 | 诱人的乳峰奶水hd | 亚洲福利二区 | aa在线| 亚洲www色| 在线免费看av | 在线观看av一区二区 | 综合久久久久久 | 欧美日韩一卡二卡三卡 | 久操视频在线 | 懂色av一区二区三区免费 | 麻豆av网址 | 亚洲国产高清国产精品 | 欧美日韩精品一区二区三区四区 | 日本不卡视频一区二区 | 91爱爱影院 | 蜜臀av中文字幕 | 美女擦边视频 | 亚洲综合色婷婷 | 久久久久久久久黄色 | 亚洲国产精品久久久久婷婷老年 | 国产无码精品在线观看 | 欧美成年人 | 视频一区二区在线播放 | 美女黄视频大全 | 偷拍亚洲综合 | 香港日本韩国三级网站 | 日本久久精品视频 | 亚洲精品久久久久国产 | 国产毛片久久久久久国产毛片 | 未满十八岁禁止进入 | 日韩精品1区2区 | 竹菊影视日韩一区二区 | 国产大屁股喷水视频在线观看 | 亚洲va久久久噜噜噜无码久久 | 反差在线观看免费版全集完整版 | 91精产国品一二三 | 能看av的网址 | 免费久久久| 人妻大战黑人白浆狂泄 | 色女仆影院| 日韩精品免费一区二区 | 三年在线观看视频 | 九九久久久 | 黄色av网站在线观看 | 伊人久久青青草 | 亚洲国产日本 | 欧美爽爽爽 | 亚洲天堂伦理 | 亚洲成人二区 | 亚洲天堂网站 | 136fldh导航福利微拍 | 中文字幕国产综合 | 日韩乱码一区二区三区 | 黑人一区二区 | 免费一级suv好看的国产网站 | 操操操av| 中文字幕中文在线 | 国产chinasex麻豆videos | 欧美在线色视频 | 国产毛片a级 | 69xx免费视频| 成人av免费 | 麻豆视频免费 | 鲁一鲁一鲁一鲁一av |