2048 Problem L 与7无关的数

389 篇文章 1 订阅
144 篇文章 2 订阅

问题 L: 与7无关的数
时间限制: 1 Sec 内存限制: 32 MB
献花: 30 解决: 27
[献花][花圈][TK题库]
题目描述

一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,
则称其为与7相关的数.现求所有小于等于n(n<100)的与7无关的正整数的平方和。

输入

案例可能有多组。对于每个测试案例输入为一行,正整数n,(n<100)

输出

对于每个测试案例输出一行,输出小于等于n的与7无关的正整数的平方和。

样例输入
6
12
18
样例输出
91
601
1575

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <ctime>
using namespace std;

bool ReW7(int a)
{
    if (a % 7 == 0)return false;
    while (a && a % 10 != 7)
        a /= 10;
    if (a)return false;
    return true;
}

int main()
{
#ifdef _DEBUG
    //freopen("data.txt", "r+", stdin);
    fstream cin("data.txt");
#endif // _DEBUG

    const int MaxN = 110;
    int n, curMax = 0, Pow[MaxN] = {0};
    while (cin >> n)
    {
        if (curMax < n)
        {
            for (int i = max(1, curMax); i <= n; ++i)
                ReW7(i)?Pow[i] = Pow[i - 1] + i * i:Pow[i] = Pow[i - 1];

            curMax = n;
        }
        cout << Pow[n] << endl;
    }


#ifdef _DEBUG
    cin.close();
#ifndef _CODEBLOCKS
    system("pause");
#endif // !_CODEBLOCKS
#endif // _DEBUG

    return 0;
}
/**************************************************************
    Problem: 2048
    User: Sharwen
    Language: C++
    Result: 升仙
    Time:0 ms
    Memory:1704 kb
****************************************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值