1.5 39: Numbers not related to 7

Describe
a positive integer, if it is divisible by 7, or the number in a certain place in its decimal representation is 7, then it is called a number related to 7. Now find all the numbers less than or equal to n (n <100) The sum of squares of positive integers not related to 7.

Input The
input is one line, and the positive integer n (n <100) is
output. The
output line contains an integer, that is, the sum of the squares of all positive integers that are less than or equal to n and not related to 7.
Sample input
21
Sample output
2336

#include <iostream>
using namespace std;
int main()
{
    
    
	int n,r=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
    
    
		if(i%7==0 || i%10==7 || i/10==7)
		{
    
    
			continue;
		}
		r += i*i;
	}
	cout<<r<<endl;
	return 0;
}
n = int(input())
r = 0
for i in range(1, n+1):
    if i%7==0 or i%10==7 or i//10==7:
        continue
    r += i*i
print(r)

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/112966651
39