题目链接;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. c#隐式转换之有符号位转换

    有符号位类型的转换,额外的高位用源表达式的符号位填充.这样就维持了被转换的值的正确符号和大小. 特别注意的是负数的转换,额外的高位用1填充,因为负数的二进制表示是对应正数的二进制取反加1,所以高位用1 ...

  2. C# == 和equals()区别

    如以下代码: ? 1 2 3 4 5 int age = 25; short newAge = 25; Console.WriteLine(age == newAge);  //true Consol ...

  3. 如果使用的是orm,是否还需要关系索引

    简而言之:是的,仍然需要理解索引,即使是使用对象关系映射(ORM)工具. ORM工具能够产生符合逻辑的,合法的查询(多数的时候),除非只是生成非常基本的查询(例如仅是根据主键查询的),否则它很难生成适 ...

  4. ios 中获得应用程序名称和版本号

    IOS程序中的应用名称和版本号在 info.plist 文件中存储着,要想在程序中获得需要使用 NSBundle 对象 下面是示例代码: NSBundle *bundle = [NSBundle ma ...

  5. 手写 title 提示

    jquery实现 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  6. twisted(1)--何为异步

    早就想写一篇文章,整体介绍python的2个异步库,twisted和tornado.我们在开发python的tcpserver时候,通常只会用3个库,twisted.tornado和gevent,其中 ...

  7. MVC中的模型注解

    authour: chenboyi updatetime: 2015-04-26 21:28:42 friendly link:   目录: 1,思维导图 2,内容解析 3,CodeSimple 1, ...

  8. java中dynamic web project与web project 的区别 [转]

    原帖地址:http://blog.sina.com.cn/s/blog_46726d2401013jlk.html 文章框架: 1.Dynamic  Web Project 概念 2.eclipse ...

  9. matplotlib绘制精美的图表(这是教程哦)

    http://sebug.net/paper/books/scipydoc/matplotlib_intro.html

  10. linux下的工具总结

    1. 编译阶段 gcc: -Wall -Werror -O2 make nm: nm -C a.o c++filt strip objdump readelf 2. 链接 ldd: ldd ./a.o ...