zoukankan      html  css  js  c++  java
  • 100c之29:求具有abcd= ( ab + cd )^2 性质的四位数

    问题

    求具有abcd= ( ab + cd )2 性质的四位数

    分析

    穷举,这个题目穷举过程也有一些技巧,比如只有 ab+cd 的个位数平方的个位数等于d才有可能。 比如2025, 20+25=45, 45的个位数是5等于d。 再比如3027绝对不可能,因为30+27=57的个位数平方等于49不等于d。

    解决方案

     1:  /**
     2:   * @file   029c.c
     3:   * @author Chaolong Zhang <emacsun@163.com>
     4:   * @date   Fri May 31 14:39:10 2013
     5:   * 
     6:   * @brief  求具有abcd= ( ab + cd )^2 性质的四位数
     7:   */
     8:  
     9:  #include <stdio.h>
    10:  
    11:  int main(int argc, char *argv[])
    12:  {
    13:      int n;
    14:  
    15:      for (n=1000; n <= 9999; ++n)
    16:      {
    17:          int temp;
    18:          temp = n/100 + n%100;
    19:          if ( ( temp%10 ) * ( temp %10 ) %10 == n%10 &&  temp * temp == n )
    20:                  printf ("%d = ( %d + %d )^2  \n",n ,n/100, n%100 );
    21:      }
    22:      return 0;
    23:  }
    

    运行结果

    2025 = ( 20 + 25 )^2  
    3025 = ( 30 + 25 )^2  
    9801 = ( 98 + 1 )^2 
    
  • 相关阅读:
    css中的属性
    css初识和css选择器
    前端html的简单认识
    数据库进阶了解
    数据库索引
    pymysql模块
    数据库的多表查询
    数据库中的行操作
    数据库和表操作以及完整性约束
    数据库概述
  • 原文地址:https://www.cnblogs.com/chaolong/p/3110397.html
Copyright © 2011-2022 走看看