UVA 10515 - Powers Et Al.(数论)
UVA 10515 - Powers Et Al.
题意:求出m^n最后一位数
思路:因为m和n都非常大,直接算肯定是不行的,非常easy想到取最后一位来算,然后又非常easy想到最后一位不断乘自身肯定会形成周期。而且这个周期还挺短的,于是先求出周期,然后用n去取模该周期求出答案是第几个就可以
代码:
#include <stdio.h>
#include <string.h> int t[10];
int save[10][10];
char n[105], m[105]; int solve(int num) {
int lenn = strlen(n);
int mod = 0;
for (int i = 0; i < lenn; i++) {
mod = (mod * 10 + n[i] - '0') % num;
}
mod--;
if (mod < 0) mod = num - 1;
return mod;
} int main() {
for (int i = 0; i < 10; i++) {
int tmp = i;
save[i][t[i]++] = i;
tmp = tmp * i % 10;
while (tmp != i) {
save[i][t[i]++] = tmp;
tmp = tmp * i % 10;
}
}
while (~scanf("%s%s", m, n)) {
if (strcmp(m, "0") == 0 && strcmp(n, "0") == 0) break;
int start = m[strlen(m) - 1] - '0';
printf("%d\n", save[start][solve(t[start])]);
}
return 0;
}
UVA 10515 - Powers Et Al.(数论)的更多相关文章
- uva 11246 - K-Multiple Free set(数论)
题目链接:uva 11246 - K-Multiple Free set 题目大意:给定n,k.求一个元素不大于n的子集,要求该子集的元素尽量多,而且不含两个数满足a∗k=b. 解题思路:容斥原理.f ...
- uva 11300 - Spreading the Wealth(数论)
题目链接:uva 11300 - Spreading the Wealth 题目大意:有n个人坐在圆桌旁,每个人有一定的金币,金币的总数可以被n整除,现在每个人可以给左右的人一些金币,使得每个人手上的 ...
- UVA 11426 - GCD - Extreme (II) (数论)
UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...
- UVA 1426 - Discrete Square Roots(数论)
UVA 1426 - Discrete Square Roots 题目链接 题意:给定X, N. R.要求r2≡x (mod n) (1 <= r < n)的全部解.R为一个已知解 思路: ...
- Uva - 12050 Palindrome Numbers【数论】
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然 ...
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- UVa 1642 - Magical GCD(数论)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 1341 - Different Digits(数论)
UVA 1341 - Different Digits 题目链接 题意:给定一个正整数n.求一个kn使得kn上用的数字最少.假设同样,则输出值最小的 思路: 首先利用鸽笼原理证明最多须要2个数字去组成 ...
- uva 10515 规律打表
Problem G Power et al. Input: Standard Input Output: Standard Output Finding the exponent of any num ...
随机推荐
- [Python随笔]>>字符串大小写是如何转换的?
首先看下Python的源码 Emmmm,说明是底层的C实现的,所以只放了说明 再看看别人家孩子的博客:https://blog.csdn.net/world6/article/details/6994 ...
- luogu P1516 青蛙的约会(线性同余方程扩展欧几里德)
题意 题解 做了这道题,发现扩欧快忘了. 根据题意可以很快地列出线性同余方程. 设跳了k次 x+mkΞy+nk(mod l) (m-n)kΞ-(x-y)(mod l) 然后化一下 (m-n)k+(x- ...
- codeforces 914 D Bash and a Tough Math Puzzle
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #i ...
- 使用systemctl自定义系统服务
1.创建系统服务文件,格式如下: [Unit] Description=httpd After=network.target [Service] Type=forking ExecStart=/usr ...
- man 7 glob
GLOB(7) Linux Programmer's Manual GLOB(7) NAME glob - 形成路径名称 描述 (DESCRIPTION) 很久以前 在 UNIX V6 版 中 有一个 ...
- Vue异步组件Demo
Vue异步组件Demo 在大型应用中,我们可能需要将应用拆分为多个小模块,按需从服务器下载.为了进一步简化,Vue.js 允许将组件定义为一个工厂函数,异步地解析组件的定义.Vue.js 只在组件需要 ...
- root用户删除文件提示:Operation not permitted
root用户删除文件提示:Operation not permitted http://blog.csdn.net/evanbai/article/details/6187578
- LeetCode 之 Merge Sorted Array(排序)
[问题描写叙述] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array ...
- sublime搜索和替换--多文件搜索替换
Search and Replace - Multiple Files Searching To open the search panel for files, press Ctrl + Shift ...
- php7-swoole-Class 'swoole_websocket_server' not found 问题
标签(空格分隔): php 分析 nginx/apache 读取的php.uini 文件 和 cli模式的php.ini 文件不同导致的 swoole是在cli模式下运行的 或许你安装swoole扩展 ...