余数 2015广工校赛 C 魔幻任务
题意:问n位最小能整除47的数字
分析:打表发现前面都是100000...,后两位就是100000%47后到47的距离,就是快速幂求1000000%47的值,47-它就是后两位
#include <bits/stdc++.h>
using namespace std; const int A = 47; int pow_mod(int x, int n, int p) {
int ret = 1;
while (n) {
if (n & 1) ret = 1ll * ret * x % p;
x = 1ll * x * x % p;
n >>= 1;
}
return ret;
} int run(int n) {
return A - pow_mod (10, n, A);
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n; scanf ("%d", &n);
if (n <= 0) puts ("-1");
else if (n == 1) puts ("0");
else if (n == 2) puts ("47");
else {
printf ("1");
for (int i=1; i<=n-3; ++i) printf ("0");
int x = run (n - 1);
if (x < 10) printf ("0%d\n", x);
else printf ("%d\n", x);
}
} return 0;
}
余数 2015广工校赛 C 魔幻任务的更多相关文章
- 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT
2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...
- 2015北京网络赛 J Scores bitset+分块
2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...
- 2015北京网络赛 Couple Trees 倍增算法
2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道. 解法来自 q ...
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- 2015年辽宁省赛Interesting Tree
题目描述 Recently, Miss Huang want to receive a Tree as her birthday gift! (What a interesting person!) ...
- 浙江理工2015.12校赛-A
孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...
- HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 5510 Bazinga (2015沈阳现场赛,子串判断)
Bazinga Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 5512 Pagodas (2015沈阳现场赛,找规律+gcd)
Pagodas Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
随机推荐
- 'XCTest/XCTest.h' file not found
直接写解决方法吧:在报错的 Target 中的 Building Settings 中 Framework Search Paths 里面添加 $(PLATFORM_DIR)/Developer/Li ...
- 25个增强iOS应用程序性能的提示和技巧(高级篇)(1)
25个增强iOS应用程序性能的提示和技巧(高级篇)(1) 2013-04-16 14:56 破船之家 beyondvincent 字号:T | T 在开发iOS应用程序时,让程序具有良好的性能是非常关 ...
- css+html 关于文本的总结(整理中)
布局1:固定行数 <div> <p>示例文字示例文字示例文字示例文字</p> </div> <!-- CSS代码 --> div{ widt ...
- apache ab下载测试
http://httpd.apache.org/docs/2.0/programs/ab.html-->http://httpd.apache.org/docs/current/platform ...
- 查询局域网内在线电脑IP
COLOR 0A CLS @ECHO Off Title 查询局域网内在线电脑IP :send @ECHO off&setlocal enabledelayedexpansion ECHO 正 ...
- Caffe初试(一)win7_64bit+VS2013+Opencv2.4.10+CUDA6.5配置Caffe环境
折腾了几天,终于在windows系统上成功配置了Caffe环境,期间遇到了很多问题,每个问题的解决也都花了不少时间,查过挺多资料,感觉挺有意义,这里写篇博客记录一下. 原来我使用的CUDA版本是7.5 ...
- AngularJS 简介、指令、表达式
AngularJS 是一个 JavaScript 框架.它可通过 <script> 标签添加到 HTML 页面. AngularJS 通过指令扩展了 HTML,且通过表达式绑定数据到 HT ...
- linux 下查mac
sh-4.1# cat /sys/class/net/eth0/address 4c:cc:6a::9a: sh-4.1# ifconfig -a |grep 'HWaddr'|awk '{print ...
- 设置tomcat内存设定
Linux: 在/usr/local/apache-tomcat-/bin 目录下的catalina.sh添加: JAVA_OPTS='-Xms512m -Xmx1024m'要加"m&quo ...
- 数据结构和算法 – 10.集合
集合: 联合.交叉.差异.子集 using System; using System.Collections; using System.Collections.Generic; using Syst ...