當(dāng)前位置:
首頁 >
CodeForces - 1512G Short Task(欧拉筛求因子和)
發(fā)布時(shí)間:2024/4/11
39
豆豆
生活随笔
收集整理的這篇文章主要介紹了
CodeForces - 1512G Short Task(欧拉筛求因子和)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接:點(diǎn)擊查看
題目大意:設(shè) d(n)d(n)d(n) 為 nnn 的約束和,更具體的,d(n)=∑k∣nkd(n)=\sum_{k|n}kd(n)=∑k∣n?k
現(xiàn)在有 mmm 次詢問,每次給出一個(gè) ccc ,需要回答滿足 d(n)=cd(n)=cd(n)=c 的最小 nnn
題目分析:預(yù)處理一下就可以了,屯一個(gè) O(n)O(n)O(n) 求因子和的板子
代碼:
// Problem: G. Short Task // Contest: Codeforces - Codeforces Round #713 (Div. 3) // URL: https://codeforces.com/contest/1512/problem/G // Memory Limit: 512 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org)// #pragma GCC optimize(2) // #pragma GCC optimize("Ofast","inline","-ffast-math") // #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<iostream> #include<cstdio> #include<string> #include<ctime> #include<cmath> #include<cstring> #include<algorithm> #include<stack> #include<climits> #include<queue> #include<map> #include<set> #include<sstream> #include<cassert> #include<bitset> #include<list> #include<unordered_map> #define lowbit(x) x&-x using namespace std; typedef long long LL; typedef unsigned long long ull; template<typename T> inline void read(T &x) {T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f; } template<typename T> inline void write(T x) {if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0'); } const int inf=0x3f3f3f3f; const int N=1e7+100; int pri[N],psum[N],sum[N],cnt; bool vis[N]; int ans[N]; void P() {sum[1]=1;for(int i=2;i<N;i++) {if(!vis[i]) {pri[cnt++]=i;psum[i]=sum[i]=i+1;}for(int j=0;j<cnt&&pri[j]*i<N;j++) {vis[i*pri[j]]=true;if(i%pri[j]==0) {psum[i*pri[j]]=psum[i]*pri[j]+1;sum[i*pri[j]]=sum[i]/psum[i]*psum[i*pri[j]];break;}psum[i*pri[j]]=pri[j]+1;sum[i*pri[j]]=sum[i]*psum[i*pri[j]];}} } int main() { #ifndef ONLINE_JUDGE // freopen("data.in.txt","r",stdin); // freopen("data.out.txt","w",stdout); #endif // ios::sync_with_stdio(false);P();memset(ans,inf,sizeof(ans));for(int i=1;i<N;i++) {if(sum[i]<N) {ans[sum[i]]=min(ans[sum[i]],i); }}int w;cin>>w;while(w--) {int n;read(n);printf("%d\n",ans[n]==inf?-1:ans[n]);}return 0; }總結(jié)
以上是生活随笔為你收集整理的CodeForces - 1512G Short Task(欧拉筛求因子和)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前缀和公式
- 下一篇: CodeForces - 1504C B