1. 程式人生 > >牛客網——與7無關的數

牛客網——與7無關的數

題目描述

一個正整數,如果它能被7整除,或者它的十進位制表示法中某個位數上的數字為7, 則稱其為與7相關的數.現求所有小於等於n(n<100)的與7無關的正整數的平方和。

輸入描述:

案例可能有多組。對於每個測試案例輸入為一行,正整數n,(n<100)

輸出描述:

對於每個測試案例輸出一行,輸出小於等於n的與7無關的正整數的平方和。

連結:https://www.nowcoder.com/questionTerminal/776d401bf86d446fa783f0bef7d3c096
來源:牛客網

import java.util.*;
public class
Main { public static void main(String[] args) { Scanner reader = new Scanner(System.in); int n = reader.nextInt(); int sum = 0; for (int i = 0; i <= n; ++i) { if ((i >= 7 && i % 7 == 0) || i % 10 == 7 || i / 10 == 7) { continue
; } sum += i*i; } System.out.println(sum); } }