Rightmost Digit
http://acm.hdu.edu.cn/showproblem.php?pid=1061
题解:快速幂
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N];
char str;
struct node{};
ll power(ll a,ll b, ll c){ll res=1;ll base=a%c;while(b){if(b&1)res=(base*res)%c;base=(base*base)%c;b>>=1;}return res;
}
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);scanf("%d",&t);while(t--){scanf("%d",&n);cout<<power(n,n,10)<<endl;}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}
Rightmost Digit相关推荐
- 震惊! Rightmost Digit 快速幂解决
题目 Given a positive integer N, you should output the most right digit of N^N. Input The input contai ...
- HDU1061 Rightmost Digit【快速模幂】
问题链接:HDU1061 Rightmost Digit. 问题简述:参见上述链接. 问题分析:一个简单的快速模幂计算. 程序说明:快速模幂计算被封装到一个函数中,直接调用即可. 题记:(略) AC的 ...
- HDU 1061 Rightmost Digit
解题报告:1097的翻版,求 N^N 次方的个位是多少? 详见我的另一篇HDU 1097 A hard puzzle稍加修改就行 1 #include<cstdio> 2 int main ...
- 【hdu 1061】Rightmost Digit(水题 快速幂 分治)
题目分析: 虽然只要求pow(x,x)%10,但是思路和求快速幂pow(x,y)%mod一样. 前者相当于后者的简化版. 解题思路 若次数y为1,则pow(x,1)%mod = x%mod; 若次数y ...
- (HDU)1061 --Rightmost Digit( 最右边的数字)
题目链接:http://vjudge.net/problem/HDU-1061 这个题目要求出N个N相乘的个位,直接求结果肯定数据溢出. 其实只要每次得出一个数字保留个位和N相乘就可以了, 因为A*B ...
- 快速幂(二进制理解)
一.题目背景 已知底数a,指数b,取模值mod. 求ans = a^b % mod 二.朴素算法(已知可跳过) ans = 1,循环从 i 到 b ,每次将 ans = ans * a % mo 时间 ...
- t-sql存储过程_使用T-SQL进行存储过程中ORDER BY的精确控制
t-sql存储过程 介绍 (Introduction) The T-SQL ORDER BY clause sorts SQL Server SELECT statement result sets, ...
- 利用T-SQL动态定义重复SQL Server数据库表行
介绍 (Introduction) Lever T-SQL to handle duplicate rows in SQL Server database tables article highlig ...
- UVA347 LA5455 Run【迭代+打表】
An N-digit runaround number is characterized as follows: • It is an integer with exactly N digits, e ...
最新文章
- Nginx自定义模块编写:根据post参数路由到不同服务器
- 500线电机光电码盘
- windows命令行帮助文档如何使用
- Qt中的QFileDialog
- php脏在哪里,逍遥游户外联盟-人身上最“脏”的地方是哪里?3个地方,建议经常清洗 -...
- 计算用户输入的数字的平均数,并输出大于平均数的数字输出
- Animation Studio插件怎么用?Nitrozme Animation Studio Packages Mac(AE插件拓展包) 安装教程
- 关于人行acs对账不及时_记工记账新方法,不用本子不用笔,一个手机全搞定
- c语言中变量的属性,C中的属性变量
- 传统春节海报设计没有思路?
- Asp.net MVC权限设计思考 (二)逻辑部分实现
- bzoj3514 Codechef MARCH14 GERALD07加强版 lct预处理+主席树
- CTF杂项题解题思路与方法
- 如何用Easy CHM制作CHM格式电子书(帮助文档)
- unbuntu: no network selected for sharing
- 职场新人必修之苦逼初感悟
- 请求服务器显示非法请求,请求被服务器识别为非法请求, 但使用 postman/curl 可以正常通过...
- 已解决:win11无法连接网络共享打印机的方法
- ps进行透视变换(扭曲变换)
- Ansible批量管理Windows服务器,winrm配置
热门文章
- python运行的原理_Python运行机制(转)
- php表单服务器验证失败,php 表单验证代码(验证失败显示提示信息)
- zk服务器系统,windows系统搭建zookeeper服务器的教程
- c语言计算机二级考试内容,2017计算机二级考试内容C语言
- 用c++来开发php的底层模块|用c++来开发apache模块,Apache模块开发实例(2)
- python中用str乘方_Python基础知识
- java compareandset 包_在Java中,AtomicInteger compareAndSet()和synced关键字的性能如何?...
- 【机器学习算法】XGBoost
- Nginx安装及其编译命令、详细教程
- 四十六、深入Java的网络编程(下篇)