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个不降数 ...
随机推荐
- 如何修改Linux系统下的PATH(如何添加自己的路径到PATH)
修改Linux的PATH方法有三(添加用户的路径到PATH): 方法一: 直接在命令行中输入:#PATH=$PATH:/etc/apache/bin.这种方法只对当前会话有效,也就是说每当登出或注销系 ...
- 【POJ1753】Flip Game
[题目大意] 有一个4x4规格的一个棋盘,现在有16个一面黑一面白的棋子分布在这个棋盘上. 翻转一个棋子能够使它以及它上下左右的四个棋子从黑变白,从白变黑. 现在问你至少要经过多少次操作才能够使得整个 ...
- 分享Git的一些个人配置
先贴上自己.gitconfig的相关命令,我再具体说一下 diff.external=~/.git-meld.sh http.sslverify=false http.proxy=http://127 ...
- gdb调试带参数程序(转:笑笑小白,cnblog http://www.cnblogs.com/rosesmall/archive/2012/04/10/2440514.html)
一般来说GDB主要调试的是C/C++的程序.要调试C/C++的程序,首先在编译时,我们必须要 把调试信息加到可执行文件中.使用编译 器(cc/gcc/g++)的 -g 参数可以做到这一点.如: > ...
- Java学习----main详解
public class Test1 { public static void main(String[] args) { System.out.println("Hello"); ...
- [转自已]Windos多个文件快速重命名说明+图解
转自己以前的文章,给新博客带点气氛. 1.(复制的)比如在文件夹中包含yin.jpg.ye.jpg.zou.jpg三个文件,你希望将它们命名为"photo+数字"的文件名形式,那么 ...
- js获取本月、三个月、今年的日期插件dateHelp
最近看了一些关于面向对象的知识,最近工作中在做统计查询的时候需要用到本月.近三个月.今年的日期范围,所以下面用用面向对象的思想写了一个获取日期的插件,大家可以借鉴使用. 直接通过new DateHel ...
- 配置was7、并部署发布项目!
1:进入服务器,选择WebSphere Application Server,进入server1,右侧进入服务器基础结构,进入java和进程管理,进入进程定义 2:在页面左边菜单中选择java虚拟机, ...
- php中jsonp的跨域实例
我们现在www.test.com这个域名下面有这么个html文件testjsonp.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- connect函数
TCP客户用connect函数来建立与TCP服务器的连接 int connect (int sockfd, const sockaddr * servaddr, socklen_t addrlen); ...