zoukankan      html  css  js  c++  java
  • 个位数为6且被3整除的五位数有多少?

    个位数为6且被3整除的五位数有多少?

    个位数为6且被3整除的五位数有多少?

    Table of Contents

    1 问题

    个位数为6且被3整除的五位数有多少?

    2 分析

    能被3整除的数其每一位上的数字相加一定能被3整除,现在已知个位数能被3整除。所以只要保证这个五位数的前四位数上的数字之和能被3整除即可。所以问题化简为:求从1000到9999的四位数能被3整除的有几个。 只要把这四位数的每个数字得到再求和,然后得到的和数与3求余即可。

    3 解决方案

     1:  /**
     2:   * @file   018c.c
     3:   * @author Chaolong Zhang <emacsun@163.com>
     4:   * @date   Sat May 18 21:41:48 2013
     5:   *
     6:   * @brief  个位数是6且能被3整除的五位数一共有多少个
     7:   *
     8:   *
     9:   */
    10:  
    11:  #include <stdio.h>
    12:  
    13:  int main(int argc, char *argv[])
    14:  {
    15:    int count=0;
    16:    int n1,n2,n3,n4;
    17:  
    18:    for (int i = 1000; i <= 9999; ++i)
    19:    {
    20:      n1=i%10;
    21:      n2=(i/10)%10;
    22:      n3=(i/100)%10;
    23:      n4=(i/1000);
    24:      if (0== (n1+n2+n3+n4)%3 ) count++;
    25:    }
    26:    printf ("the total number is %d\n", count);
    27:    return 0;
    28:  } 
    

    Date:

    Author: emacsun

    Org version 7.8.02 with Emacs version 23

    Validate XHTML 1.0
  • 相关阅读:
    记MongoDB的安装
    Python格式化输出指定宽度及占位符
    LMDB数据库加速Pytorch文件读取速度
    IDEA设置输入后自动提示
    IDEA2020 最新激活
    java 编译执行cmd命令
    算法9:What is the sum of the digits of the number 21000
    JAVA8 LocalDateTime
    算法8:已知 a^2+b^2=c^2(a,b,c 为自然数,a<b<c),且a+b+c=1000,求abc的值?
    ROS学习笔记
  • 原文地址:https://www.cnblogs.com/chaolong/p/3086240.html
Copyright © 2011-2022 走看看