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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【牛客 - 327牛客寒假算法基础集训营2 I】处女座的测验(二)(积性函数性质,数论,素数唯一性分解,STL)

發(fā)布時間:2023/12/10 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【牛客 - 327牛客寒假算法基础集训营2 I】处女座的测验(二)(积性函数性质,数论,素数唯一性分解,STL) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

鏈接:https://ac.nowcoder.com/acm/contest/327/I
來源:??途W(wǎng)
?

現(xiàn)在處女座順利的完成了測驗,處女座想要知道知道自己輸出的結(jié)果是否正確。他希望知道自己有自己輸出的數(shù)中有多少對是不滿足要求的。

?

更具體的,處女座想知道下面程序段的答案

int main()

{

???????? int n;

? ? ? ? ?cin>>n;

???????? for (int i=1;i<=n;i++)

?????????????????? cin>>a[i];

???????? int ans=0;

???????? for (int i=1;i<=n;i++)

???????? {

?????????????????? for (int j=i+1;j<=n;j++)

?????????????????? {

? ? ? ? ? ? ? ? ? ? ? ? ? ??if(τ(a[i]?a[j])≤10)ans=ans+1;if(τ(a[i]?a[j])≤10)ans=ans+1;

?????????????????? }

???????? }

???????? cout<<ans<<endl;

???????? return 0;

}

其中為n的因子的個數(shù)

輸入描述:

兩行

第一行一個整數(shù)n

第二行n個整數(shù),a1,a2,…,an

2<=n<=2000, 1<=ai<=3*108

輸出描述:

一行,一個整數(shù)ans

示例1

輸入

復(fù)制

7 34 45 23 12 63 23 90

輸出

復(fù)制

3

備注:

不保證任意兩個整數(shù)互質(zhì)

解題報告:

? 直接暴力求解,因為該范圍內(nèi)的數(shù)分解成素數(shù)最多就9個,再加上大于4個就剪枝,所以n^2log10完全不會超時。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<unordered_map> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 2e4 + 5; int n,a[MAX]; //vector<int> vv[MAX]; map<int,int> mp[MAX]; void ff(int id,int x) {for(int i = 2; i*i<=x; i++) {int cnt = 0;if(x%i == 0) {while(x%i==0) x/=i,cnt++; mp[id][i] = cnt;}}if(x > 1) mp[id][x] = 1; } int main() {cin>>n;for(int i = 1; i<=n; i++) scanf("%d",a+i),ff(i,a[i]);int ans = 0;for(int i = 1; i<=n; i++) {if(mp[i].size() >= 4) continue;for(int j = i+1; j<=n; j++) {if(mp[j].size() >= 4) continue;int nums = 1;for(auto it : mp[i]) {int fac = it.first;int num = it.second;if(mp[j].find(fac) != mp[j].end()) {nums *= (num + mp[j][fac]+1);}else nums *= (num+1); }for(auto it : mp[j]) {int fac = it.first;int num = it.second;if(mp[i].find(fac) == mp[i].end()) nums *= (num+1);}if(nums <= 10) ans++;}} printf("%d\n",ans);return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【牛客 - 327牛客寒假算法基础集训营2 I】处女座的测验(二)(积性函数性质,数论,素数唯一性分解,STL)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。