博客
关于我
A. Arpa’s hard exam and Mehrdad’s naive cheat
阅读量:799 次
发布时间:2019-03-24

本文共 1065 字,大约阅读时间需要 3 分钟。

最后一位数字的计算方法

对于给定的整数n,计算1378乘以n后结果的最后一位数字。这是一个简便的数学问题,可以通过观察乘法的规律来解决,而不需要实际进行大数运算。

相关知识点

  • 最后一位数字的周期性:乘法的最后一位数字具有周期性。例如,乘以8的最后一位数字每4次重复一次。

    8 × 1 = 8 → 最后一位是8

    8 × 2 = 16 → 最后一位是6
    8 × 3 = 24 → 最后一位是4
    8 × 4 = 32 → 最后一位是2
    8 × 5 = 40 → 最后一位是0
    8 × 6 = 48 → 最后一位是8
    ...循环往复。

  • 312整体的最后一位数字:我们可以专注于研究1378这个数的最后一位数字,即8。因为其他位数对乘法的最后一位没有影响。

绝对值方法

  • 首先,我们可以将n分解为不同的乘法部分,逐步计算它们对最后一位数字的影响。

    1378 = 1000 + 300 + 78 = 1000 + 300 + 70 + 8

  • 由于1000、300和70中的最后一位数字都是0,其对乘法的最后一位数字没有影响。因此,实际上我们只需要关注8这个数字。

  • 因此,1378 × n 的最后一位数字等于 8 × n 的最后一位数字。

如何快速计算

由于8 × n 的最后一位数字具有周期性,循环周期为4。我们可以通过观察n模4的值来确定结果:

n的取值范围 8 × n的最后一位数字 对应的n模4的值
0-1 8 0,1
2-3 6,4 2,3
4 2 0
5-7 0,8,6,4 1,2,3,0
... ... ...

通过这种方式,我们可以直接根据n的最后一位数和n模4的值快速确定1378 × n的最后一位数字。

示例

  • 当n=1时:8×1=8 → 最后一位是8。

  • 当n=2时:8×2=16 → 最后一位是6。

  • 当n=3时:8×3=24 → 最后一位是4。

  • 当n=4时:8×4=32 → 最后一位是2。

  • 当n=5时:8×5=40 → 最后一位是0。

  • 实现方式

    • 使用编程语言(例如C++)实现一个简单的arithmetics运算。
    • 读取输入n,计算最后一位数字。
    #include 
    using namespace std;int main() { int n; cin >> n; int result = (8 * n) % 10; cout << result; return 0;}

    注意事项

    • 当n=0时,乘法结果为0,最后一位数字为0。
    • 如果n较大时,可以使用模运算来优化计算过程。

    转载地址:http://kxakk.baihongyu.com/

    你可能感兴趣的文章
    npm学习(十一)之package-lock.json
    查看>>
    npm安装 出现 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! 解决方法
    查看>>
    npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
    查看>>
    npm安装教程
    查看>>
    npm报错Cannot find module ‘webpack‘ Require stack
    查看>>
    npm报错Failed at the node-sass@4.14.1 postinstall script
    查看>>
    npm报错fatal: Could not read from remote repository
    查看>>
    npm报错File to import not found or unreadable: @/assets/styles/global.scss.
    查看>>
    npm报错TypeError: this.getOptions is not a function
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
    查看>>
    npm版本过高问题
    查看>>
    npm的“--force“和“--legacy-peer-deps“参数
    查看>>
    npm的安装和更新---npm工作笔记002
    查看>>
    npm的常用操作---npm工作笔记003
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm编译报错You may need an additional loader to handle the result of these loaders
    查看>>
    npm设置淘宝镜像、升级等
    查看>>
    npm设置源地址,npm官方地址
    查看>>