NC24762. [USACO 2010 Ope B]Cow Pals
描述
输入描述
* Line 1: A single integer: S
输出描述
* Line 1: A single line with two space-separated integers that are the serial number of the first superpal whose serial number is no smaller than S and the serial number of her pal.
示例1
输入:
206
输出:
220 284
C++14(g++5.4) 解法, 执行用时: 284ms, 内存消耗: 588K, 提交时间: 2020-04-08 16:41:35
#include<iostream> using namespace std; int main() { int n; cin>>n; while(n) { int m=0,sum=0; for(int i=1;i<n;i++) if(n%i==0) m+=i; for(int i=1;i<m;i++) if(m%i==0) sum+=i; if(sum==n&&m!=n){ cout<<sum<<" "<<m<<endl; break;} else n++; } }
C 解法, 执行用时: 116ms, 内存消耗: 340K, 提交时间: 2023-04-11 17:32:43
#include<stdio.h> int df(int a){ int i=2; int sum=0; for(i=2;i<=a/2;i++){ if(a%i==0){ sum+=i; } } sum+=1; return sum; } int main() { int s; scanf("%d",&s); int flag=1; int a,b; while(flag==1){ a=df(s); b=df(a); if(s!=a) { if(s==b){ printf("%d %d",s,df(s)); break; } } s++; } return 0; }
C++11(clang++ 3.9) 解法, 执行用时: 238ms, 内存消耗: 608K, 提交时间: 2019-10-08 17:45:36
#include<iostream> using namespace std; int main(){ int n,m; cin>>n; while(n){ int sum=0,ans=0; for(int i=1;i<n;i++){ if(n%i==0) sum=sum+i; } for(int i=1;i<sum;i++){ if(sum%i==0) ans=ans+i; } if(ans==n&&sum!=n){ cout<<ans<<" "<<sum<<endl; break; } else n++; } return 0; }
Python3 解法, 执行用时: 79ms, 内存消耗: 5220K, 提交时间: 2023-04-11 20:28:34
def disolve(x: int) -> int: ans = 1 for i in range(2, int(x ** 0.5) + 1): if x % i == 0: ans += i + x // i return ans i = int(input()) while True: n = disolve(i) if disolve(n) == i and n != i: print(i, n) break i += 1
pypy3(pypy3.6.1) 解法, 执行用时: 867ms, 内存消耗: 20260K, 提交时间: 2021-05-02 19:58:15
n=int(input()) while(n): sum1=0 ans=0 for i in range(1,n): if(n%i==0): sum1+=i; for i in range(1,sum1): if(sum1%i==0): ans+=i if(ans==n and sum1!=n): print(ans,sum1) break; else: n+=1;