题目链接;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)的更多相关文章

  1. UVALive 4998 Simple Encryption --DFS

    题意: 给出K1,求一个12位数(不含前导0)K2,使得K1^K2 mod (10^12) = K2. 解法: 求不动点问题. 有一个性质: 如果12位数K2满足如上式子的话,那么K2%1,K2%10 ...

  2. UVA - 10014 - Simple calculations (经典的数学推导题!!)

    UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...

  3. UVA - 11853 Paintball(dfs)

    UVA - 11853 思路:dfs,从最上面超过上边界的圆开始搜索,看能不能搜到最下面超过下边界的圆. 代码: #include<bits/stdc++.h> using namespa ...

  4. uva 10994 - Simple Addition(规律)

    题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...

  5. UVA.548 Tree(二叉树 DFS)

    UVA.548 Tree(二叉树 DFS) 题意分析 给出一棵树的中序遍历和后序遍历,从所有叶子节点中找到一个使得其到根节点的权值最小.若有多个,输出叶子节点本身权值小的那个节点. 先递归建树,然后D ...

  6. UVa 572 油田(DFS求连通块)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVA - 1103Ancient Messages(dfs)

    UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study te ...

  8. UVa 208 消防车(dfs+剪枝)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 12377 Number Coding --DFS

    题意:给一串数字,第一个数是Num的话,要使后面的数字组成Num个数,而且为不降的,将这Num个数分配到9个素因子上作为指数,问能组成多少个不同的数 解法:dfs一遍,看后面的数字能组成Num个不降数 ...

随机推荐

  1. datazen logo修改

    第一步:进入cp 页面 第二步: P161说明文档的P161开始,这里有说有版本的图片命名 第三步:再次强调第二步的命名,否则 如果你直接复制这个名字,不但效果出不来,还删除不掉这个包,我上次是把da ...

  2. MVC使用Exception过滤器自定义处理Action的的异常

    1.继承FilterAttribute ,IExceptionFilter自定义处理 /// <summary> /// 登录错误自定义处理 /// </summary> pu ...

  3. Linux下解决高并发socket最大连接数所受的各种限制(解除IO限制)

    linux作为服务器系统,当运行高并发TCP程序时,通常会出现连接建立到一定个数后不能再建立连接的情况 本人在工作时,测试高并发tcp程序(GPS服务器端程序),多次测试,发现每次连接建立到3800左 ...

  4. 页面d初始化加载

    1.$(document).ready(function () { alert("Hello Word!"); }); 或简写为 2.$(function(){ alert(&qu ...

  5. C# 中使用 OpenSSL 的公钥/私钥进行加密和解密

    在C#中进行RSA解密,需要用RSACryptoServiceProvider,但是不支持OpenSSL格式的公钥或者私钥. X509 公钥 -----BEGIN PUBLIC KEY----- MI ...

  6. ecshop json类的使用

    ecshop中有2个地方使用了json,一个是cls_json.php文件,一个是transport.js文件. cls_json 封装了json类,可以调用里面的encode的方法,根据参数不同,进 ...

  7. 表单数据校检方法 onsubmit()的使用?

    在项目中为一个表单(from)编写onsubmit()脚本的时候,经常需要验证表单中数据的合法性 所以常会写道:<form action="/admin/addUser.do" ...

  8. javascript 向上滚动

    <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Co ...

  9. iOS开发——常用Runtime函数

    Runtime函数 1.可以通过NSObject的一些方法获取运行时信息或动态执行一些消息:1./*Returns a Boolean value that indicates whether the ...

  10. jQuery显示与隐藏返回顶层的箭头

    <script type="text/javascript">        $(window).scroll(function(){            var d ...