1 条题解

  • 0
    @ 2025-10-10 15:45:26

    C :

    #include<stdio.h>   
    
    int main(){ 
    	int n,i,c=0;
    	scanf("%d",&n);
    	
    	
    	for(i = 1;i <= n;i++){
    		if( i % 3 == 2 && i % 5 == 3 && i % 7 == 2){
    			c++;
    		}
    	}
    	
    	printf("%d",c);
    	return 0;
    } 
    

    C++ :

    #include <iostream>
    using namespace std;
    int main(){
    	int n,i,a;
    	a=0;
    	cin>>n;
    	for(i=1;i<=n;i++){
    		if(i%3==2&&i%5==3&&i%7==2){
    		a++;	
    		}
    		
    	}
    	cout<<a<<endl;
    }
    

    Pascal :

    var
            i,n,m:integer;
    begin
            read(n);
            for i:=1 to n do
                    if (i mod 3=2) and (i mod 5=3) and (i mod 7=2) then m:=m+1;
            write(m);
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		@SuppressWarnings("resource")
    		Scanner scanner=new Scanner(System.in);
    		int m=scanner.nextInt();
            int c=0;
    			for (int a=1;a<=m;a++)
    				if (a%3==2&&a%5==3&&a%7==2)
    					c++;
    			System.out.println(c);
    		}	
    	}
    
    

    Python :

    i=1
    s=0
    n=int(input())
    while i<=n:
      a=i//1000
      b=i//100%10
      c=i//10%10
      d=i%10
      if i%3==2 and i%5==3 and i%7==2:
        s+=1
      i+=1
    print(s)
    
    • 1

    信息

    ID
    54
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    5
    已通过
    5
    上传者