uva 12253 - Simple Encryption(dfs)
题目链接;uva 12253 - Simple Encryption
题目大意:给定K1。求一个12位的K2,使得KK21=K2%1012
解题思路:按位枚举,不且借用用高速幂取模推断结果。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll ite=(1<<20)-1;
ll N;
/*
ll mul_mod (ll x, ll n, ll mod) {
ll ans = 0;
x %= mod;
n %= mod;
while (n) {
if (n&1)
ans = (ans + x) % mod;
x = 2 * x % mod;
n >>= 1;
}
return ans;
}
*/
ll mul_mod(ll a, ll b, ll mod) {
return (a * (b>>20) % mod * (1ll<<20) %mod + a*(b&(ite)) % mod) % mod;
}
ll pow_mod (ll x, ll n, ll mod) {
ll ret = 1;
while (n) {
if (n&1)
ret = mul_mod(ret, x, mod);
x = mul_mod(x, x, mod);
n >>= 1;
}
return ret;
}
bool dfs (int d, ll u, ll mod) {
if (d == 12) {
if (u >= 1e11 && pow_mod(N, u, mod) == u) {
printf("%lld\n", u);
return true;
}
return false;
}
for (int i = 0; i < 10; i++) {
if (pow_mod(N, i * mod + u, mod) == u) {
if (dfs(d+1, i * mod + u, mod * 10))
return true;
}
}
return false;
}
int main () {
int cas = 1;
while (scanf("%lld", &N) == 1 && N) {
printf("Case %d: Public Key = %lld Private Key = ", cas++, N);
for (int i = 0; i < 10; i++) {
if (dfs(1, i, 10))
break;
}
}
return 0;
}
uva 12253 - Simple Encryption(dfs)的更多相关文章
- UVALive 4998 Simple Encryption --DFS
题意: 给出K1,求一个12位数(不含前导0)K2,使得K1^K2 mod (10^12) = K2. 解法: 求不动点问题. 有一个性质: 如果12位数K2满足如上式子的话,那么K2%1,K2%10 ...
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- UVA - 11853 Paintball(dfs)
UVA - 11853 思路:dfs,从最上面超过上边界的圆开始搜索,看能不能搜到最下面超过下边界的圆. 代码: #include<bits/stdc++.h> using namespa ...
- uva 10994 - Simple Addition(规律)
题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...
- UVA.548 Tree(二叉树 DFS)
UVA.548 Tree(二叉树 DFS) 题意分析 给出一棵树的中序遍历和后序遍历,从所有叶子节点中找到一个使得其到根节点的权值最小.若有多个,输出叶子节点本身权值小的那个节点. 先递归建树,然后D ...
- UVa 572 油田(DFS求连通块)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA - 1103Ancient Messages(dfs)
UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study te ...
- UVa 208 消防车(dfs+剪枝)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 12377 Number Coding --DFS
题意:给一串数字,第一个数是Num的话,要使后面的数字组成Num个数,而且为不降的,将这Num个数分配到9个素因子上作为指数,问能组成多少个不同的数 解法:dfs一遍,看后面的数字能组成Num个不降数 ...
随机推荐
- (转)PHP中构造函数和析构函数解析
--http://www.jb51.net/article/56047.htm 构造函数 void __construct ([ mixed $args [, $... ]] ) PHP 5 允行开发 ...
- Linux安装配置mongodb
1. 下载MongoDB 2. 解压文件到某目录下,然后重命名: [root@localhost var]# tar -xzvf mongodb-linux-i686-2.0.1.tar [root@ ...
- 关于模板中的动态取值 ---反射与javascript脚本编译
在项目中经常遇到一个问题,打印word或者打印excel的时候,我们经常使用一对一的赋值或者批量替换的方式来对模板进行修改. 但是现在遇到两种场景: 1.取值是通过自定以方法进行取值的. 如:一个销售 ...
- C#串口控制
串行口是计算机的标准接口,现在的PC机(个人电脑)一般至少有两个串行口COM1和COM2.串行口应用广泛,在数据通信.计算机网络以及分布式工业控制系统中,经常采用串行通信来交换数据和信息.本节通过几个 ...
- ubuntu下安装Vmare Workstation,并安装mac补丁
最近想学习一下关于ios方面的开发,但是苦于自己的电脑已经装了两个系统:一个win7,一个ubuntu.两系统均装在物理硬盘上,不想格盘,所以装个虚拟机玩玩.决定使用Vmare Workstation ...
- JavaScript--垃圾回收器
垃圾回收: 释放不再被任何变量引用的对象 垃圾回收器: 专门记录对象的引用次数,并回收不再被引用的对象的程序. 垃圾回收器和主程序并行在后台执行 垃圾回收器会为每个对象创建一个引用计数器(counte ...
- 【USACO 1.4.1】铺放矩形块
[描述] 给定4个矩形块,找出一个最小的封闭矩形将这4个矩形块放入,但不得相互重叠.所谓最小矩形指该矩形面积最小. 所有4个矩形块的边都与封闭矩形的边相平行,图1示出了铺放 ...
- YesFInder - Web File Manager 网页文件管理系统
开发原由: 原来想找一下实现可视化图片上传程序,先找了ckfinder,发现居然是收费的,而且用起来也不顺手,于是想能不能自己写一个.想到这就立即动手,花2天时间完成初步功能,然后再花了3天完善.目前 ...
- php 用于绘图使用的颜色数组
$colorArr = array(0x912CEE, 0x99ff00, 0x312520, 0x801dae, 0x25f8cb, 0xCC3333, 0x808080, 0xa29b7c, 0x ...
- django+nginx+supervisor+gunicorn+gevent 网站部署
django+nginx+supervisor+gunicorn+gevent 网站部署 django,nginx,supervisor,gunicorn,gevent这几个都是在本领域大名鼎鼎的软件 ...