1 solutions
-
0
C :
#include<stdio.h> int main(){ int i,n,sum=0; scanf("%d",&n); if(n % 2 == 0){ //判断n是偶数还是奇数 for(i = 1;i <= n;i++){ if(n % i == 0){ //判断i是不是n的约数 sum += i; } } }else{ for(i = 1;i <= n;i++){ if(i % 2 == 0){ sum += i; } } } printf("%d",sum); return 0; }
C++ :
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(){ int a,i,s=0; cin>>a; if(a%2==0){ for(i=1;i<=a;i++){ if(a%i==0){ s=s+i; } }cout<<s<<endl; } else{ for(i=2;i<a;i=i+2){ s=s+i; }cout<<s; } }
Python :
n=int(input()) if n%2!=0: i=0 s=0 while i<n: s+=i i+=2 print(s) if n%2==0: i=1 s=0 for i in range(1,n+1): if n%i==0: s+=i i+=1 print(s)
- 1
Information
- ID
- 10838
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By