1 solutions

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

    C++ :

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    using namespace std;
    
    int main(){
        int n;
        cin>>n;
        int i,j,s=0;
        for(i=1;i<n;i++){
        	for(j=i+1;j<=n;j++){
        		if((i+j)%3==0||(i+j)%7==0){
        			s=s+1;
    			}
    		}
    	}cout<<s<<endl;
    }
    

    Python :

    n = int(input());
    i = 0
    x = 0
    s = 0
    for i in range(1,n+1):
        for x in range(i,n +1):
            if i != x:
                if (i + x) % 3 == 0 or (i + x) % 7 == 0:
                    s += 1
    print(s)
                
    
    • 1

    Information

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