题解 | #与7无关的数#

与7无关的数

https://www.nowcoder.com/practice/776d401bf86d446fa783f0bef7d3c096

//Java版代码
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 7 != 0 && i % 10 != 7) ans += i * i;
        }
        System.out.println(ans);
    }
}#Python版代码
print(sum(i * i for i in range(1, int(input()) + 1) if i % 10 != 7 and i % 7 != 0))

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务