题解 | #与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))

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 11:30
仁者伍敌:kpi都懒得刷了属于是
点赞 评论 收藏
分享
05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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