1.5 编程基础之循环控制 39与7无关的数

http://noi.openjudge.cn/ch0105/39/

#include<iostream>
using namespace std;
int main()
{
	int i,n,x,ans=0;

	cin>>n;
  
	for(i=1;i<=n;i++)
	{
		int f1=1,f2=1;
		if(i%7==0) 
		{
			f1=0;
			continue;
		}
		
		x=i;
		while(x&&f2)
		{
			if(x%10==7) 
			{
				f2=0;
				break;
			}
			x/=10;
		}
	
		if(f1&&f2) 
		{
			ans+=i*i;
		}
	
	}
	
	cout<<ans;
	
	return 0;
}

 


 

 

 

 

 


 python3代码

"""
1.5编程基础之循环控制 39与7无关的数 AC
http://noi.openjudge.cn/ch0105/39/

"""
n=int(input())
s=0
for i in range(n):
            i+=1
            if i%7!=0 and i%10!=7 and i//10!=7:
                        s+=i*i
print(s)

おすすめ

転載: blog.csdn.net/dllglvzhenfeng/article/details/121887527