zoukankan      html  css  js  c++  java
  • 20200817-与7无关的数(奥赛一本通 P68 4)

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

    自己解法:

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
      int n;
      int box=0,ls;
      cin>>n;
      for(int i=1;i<=n;++i)
        {
          if(i%7==0)
            {
              continue ;
            }

           if(i%10==7)
            {
              continue ;
            }

        ls=i/10;
        if(ls>0&&ls%10==7)
          {
              continue ;
         }
        ls=0;
        box=box+i*i;

    }

      cout<<box<<endl;
      return 0;

    }

    //书上解法

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
      int n;
      int box=0,ls;
      cin>>n;
      for(int i=1;i<=n;++i)
        {
          if(i%7!=0&&i%10!=7&&i/10!=7)
            {

              box=box+i*i; //累计平方和
            }
        }
      cout<<box<<endl;
      return 0;

    }

  • 相关阅读:
    UVa10779
    UVa10779
    C++ 内存管理学习笔记
    c++ 学习笔记
    AcWing 275 传纸条
    I
    Tree HDU6228
    Lpl and Energy-saving Lamps
    C
    Secret Poems
  • 原文地址:https://www.cnblogs.com/whcsrj/p/13515586.html
Copyright © 2011-2022 走看看