1 条题解

  • 0
    @ 2021-6-14 23:20:21

    C :

    #include<stdio.h>
    int prime(int n)
    {
    	for(int i = 2; i * i <= n; i++)
    		if(n % i == 0)
    			return 0;
    		return 1;
    }
    int main()
    {
    	int i, j, k, s;
    	int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    	for(i = 1988; i <= 1989; i++)
    	{
    		if((i % 4 == 0 && i % 100 != 0)||(i % 400) == 0)
    			a[2] = 29;
    		else
    			a[2] = 28;
    		for(j = 1; j <= 12; j++)
    			for(k = 1; k <= a[j]; k++)
    			{
    				s = i * 10000 + j * 100 + k;
    				if(prime(s))
    					printf("%d\n", s);
    			}
    	}
    }
    

    C++ :

    #include<stdio.h>
    int prime(int n)
    {
    	for(int i = 2; i * i <= n; i++)
    		if(n % i == 0)
    			return 0;
    		return 1;
    }
    int main()
    {
    	int i, j, k, s;
    	int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    	for(i = 1988; i <= 1989; i++)
    	{
    		if((i % 4 == 0 && i % 100 != 0)||(i % 400) == 0)
    			a[2] = 29;
    		else
    			a[2] = 28;
    		for(j = 1; j <= 12; j++)
    			for(k = 1; k <= a[j]; k++)
    			{
    				s = i * 10000 + j * 100 + k;
    				if(prime(s))
    					printf("%d\n", s);
    			}
    	}
    }
    
    • 1

    信息

    ID
    128
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者