1 solutions
-
0
C :
#include<stdio.h> void main(){ int i,n,s=0; scanf("%d",&n); for(i=1;i<=n;i++){ if((i%2==0&&i%3==0)||(i%2==0&&i%5==0)||(i%2==0&&i%7==0)||(i%3==0&&i%5==0)||(i%3==0&&i%7==0)||(i%5==0&&i%7==0)||(i%2==0&&i%3==0&&i%5==0)||(i%2==0&&i%3==0&&i%7==0)||(i%3==0&&i%5==0&&i%7==0)||(i%2==0&&i%3==0&&i%5==0&&i%7==0)){ s=s+i; } } printf("%d",s); }
C++ :
#include <bits/stdc++.h> using namespace std; int main(){ int n,i,c,s = 0; cin>>n; for(i = 1;i <= n;i++){ c = 0; if(i % 2 == 0){ c++; } if(i % 3 == 0){ c++; } if(i % 5 == 0){ c++; } if(i % 7 == 0){ c++; } if(c >= 2){ s = s + i; } } cout<<s<<endl; }
Python :
n=int(input()) i=1 s=0 for i in range(1,n+1): if i%6==0 or i%10==0 or i%14==0 or i%15==0 or i%21==0 or i%35==0: s+=i i+=1 print(s)
- 1
Information
- ID
- 10445
- Time
- 1000ms
- Memory
- 32MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By