1 solutions

  • 0
    @ 2025-3-3 16:33:41

    C :

    #include<stdio.h>
    
    void main(){
    	int n,i,g,s,b,c;
    	scanf("%d",&n);
    	
    	c=0;
    	for(i=1;i<=n;i++){
    		g=i%10;
    		s=i/10%10;
    		b=i/100;
    		if(i%7!=0&&(g!=7&&s!=7&&b!=7)){
    			c=c+i;
    		}
    	} 
    		printf("%d",c);
    }
    

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int i,n,g,s,b,x = 0;
    	cin>>n;
    	for(i = 1;i <= n;i++){
    		b = i / 100;
    		s = i / 10 % 10;
    		g = i % 10;
    		
    		if(i % 7 != 0 && (b != 7 && s != 7 && g != 7)){
    			x = x + i;
    		}
    	}
    	cout<<x<<endl;
    }
    
    

    Python :

    n=int(input())
    i=1
    s=0
    for i in range(1,n+1):
        a=i//100
        b=i//10%10
        c=i%10
        if i%7==0 or a==7 or b==7 or c==7:
            continue
        if i%7!=0 and a!=7 and b!=7 and c!=7:
            s+=i
            i+=1
    print(s)
    
    • 1

    Information

    ID
    10702
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By