Mod Tree

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5934    Accepted Submission(s): 1498

Problem Description

  The picture indicates a tree, every node has 2 children.
  The depth of the nodes whose color is blue is 3; the depth of the node whose color is pink is 0.
  Now
out problem is so easy, give you a tree that every nodes have K
children, you are expected to calculate the minimize depth D so that the
number of nodes whose depth is D equals to N after mod P.
 
Input
The input consists of several test cases.
Every cases have only three integers indicating K, P, N. (1<=K, P, N<=10^9)
 
Output
The minimize D.
If you can’t find such D, just output “Orz,I can’t find D!”
 
Sample Input
3 78992 453
4 1314520 65536
5 1234 67
 Sample Output
Orz,I can’t find D!
8
20
扩展baby_step,giant_step算法模板题
  1 #include<stdio.h>
2 #include<algorithm>
3 #include<queue>
4 #include<stack>
5 #include<string.h>
6 #include<iostream>
7 #include<math.h>
8 #include<map>
9 using namespace std;
10 typedef long long LL;
11 typedef struct node
12 {
13 LL val;
14 int id;
15 } ss;
16 LL quick(LL n,LL m,LL mod);
17 pair<LL,LL>ex_gcd(LL n,LL m);
18 LL gcd(LL n,LL m);
19 bool cmp(node p,node q);
20 LL g_step_b_step(LL x,LL k,LL z);
21 ss ans[100000];
22 int main(void)
23 {
24 LL x,z,k;
25 while(scanf("%lld %lld %lld",&x,&z,&k)!=EOF)
26 {
27 LL ask = g_step_b_step(x,k,z);
28 if(ask == -1||k >= z)
29 printf("Orz,I can’t find D!\n");
30 else printf("%lld\n",ask);
31 }
32 return 0;
33 }
34 LL g_step_b_step(LL x,LL k,LL z)
35 {
36 LL y = 0;
37 LL xx = 1;
38 while(true)
39 {
40 LL c = xx%z;
41 if(c == k)return y;
42 LL gc = gcd(x,z);
43 if(gc == 1)break;
44 y++;if(k%gc)return -1;
45 z/=gc;k /= gc;
46 xx = xx*(x/gc);
47 xx%=z;
48 }
49 LL zz = sqrt(z) + 1;
50 pair<LL,LL>NI = ex_gcd(x,z);
51 NI.first = (NI.first%z + z)%z;
52 LL NNI = NI.first*(k%z)%z;
53 ans[0].id = 0,ans[0].val = k;
54 for(int i = 1; i <= zz; i++)
55 {
56 ans[i].id = i;
57 ans[i].val = NNI;
58 NNI = NNI*NI.first%z;
59 }
60 sort(ans,ans+zz+1,cmp);
61 LL x1 = quick(x,zz,z);
62 LL slx = xx;
63 for(int i = 0; i <= zz; i++)
64 {
65 int l = 0,r = zz;
66 int id = -1;
67 while(l <= r)
68 {
69 int mid = (l+r)/2;
70 if(ans[mid].val >= slx)
71 {
72 id = mid;
73 r = mid - 1;
74 }
75 else l = mid + 1;
76 }
77 if(id!=-1)
78 {
79 if(ans[id].val == slx)
80 {
81 LL ask = (LL)i*zz + ans[id].id + y;
82 return ask;
83 }
84 }
85 slx = slx*x1%z;
86 }
87 return -1;
88 }
89 LL gcd(LL n,LL m)
90 {
91 if(m == 0)
92 return n;
93 else return gcd(m,n%m);
94 }
95 LL quick(LL n,LL m,LL mod)
96 {
97 n%=mod;
98 LL ask = 1;
99 while(m)
100 {
101 if(m&1)
102 ask = ask*n%mod;
103 n = n*n%mod;
104 m/=2;
105 }
106 return ask;
107 }
108 pair<LL,LL>ex_gcd(LL n,LL m)
109 {
110 if(m == 0)
111 return make_pair(1,0);
112 else
113 {
114 pair<LL,LL>ans = ex_gcd(m,n%m);
115 return make_pair(ans.second,ans.first - (n/m)*ans.second);
116 }
117 }
118 bool cmp(node p,node q)
119 {
120 if(p.val == q.val)
121 return p.id < q.id;
122 else return p.val < q.val;
123 }

Mod Tree(hdu2815)的更多相关文章

  1. HDU 2815 Mod Tree (扩展 Baby Step Giant Step )

    Mod Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. 【HDU2815】【拓展BSGS】Mod Tree

    Problem Description   The picture indicates a tree, every node has 2 children.  The depth of the nod ...

  3. HDU 2815 Mod Tree 离散对数 扩张Baby Step Giant Step算法

    联系:http://acm.hdu.edu.cn/showproblem.php?pid=2815 意甲冠军: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  4. hdu 2815 Mod Tree (exBSGS)

    http://acm.hdu.edu.cn/showproblem.php?pid=2815 //解 K^D ≡ N mod P #include<map> #include<cma ...

  5. hdu 2815 : Mod Tree 【扩展BSGS】

    题目链接 直接用模板好了.实在不行,反正有队友啊~~~~ #include<bits/stdc++.h> using namespace std; typedef long long LL ...

  6. hdu 2815 Mod Tree 高次方程,n不为素数

    Accepted 406MS 8576K 2379 B C++/** 这里加了一点限制,,大体还是一样的,, **/ #include <iostream> #include <cs ...

  7. HDU 2815 Mod Tree

    不会,先搁着…… http://blog.csdn.net/acm_cxlove/article/details/7832197

  8. 2018.9 ECNU ICPC/CCPC Trial Round #2 Query On Tree (树链剖分+线段树维护)

    传送门:https://acm.ecnu.edu.cn/contest/105/problem/Q/ 一棵树,支持两种操作:给一条路径上的节点加上一个等差数列;求两点路径上节点和. 很明显,熟练剖分. ...

  9. hdu6446 Tree and Permutation 2018ccpc网络赛 思维+dfs

    题目传送门 题目描述:给出一颗树,每条边都有权值,然后列出一个n的全排列,对于所有的全排列,比如1 2 3 4这样一个排列,要算出1到2的树上距离加2到3的树上距离加3到4的树上距离,这个和就是一个排 ...

随机推荐

  1. 学习java第十九天

    一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...

  2. ache

    ache和pain可能没啥差别,头疼和头好痛都对.从词典来看,有backache, bellyache, earache, headache, heartache, moustache/mustach ...

  3. 数仓day04----日志预处理2

    1.详细描述idmap的整个计算方案 (1)使用SparkSession对象读取用户不同类别的埋点日志,解析并抽取出相应的标识id,使用union进行合并,得到装有汇总标识id的rdd(ids) (2 ...

  4. 虚拟机中安装centos系统的详细过程

    linux-centos的安装 检查电脑是否开启虚拟化,只有开启虚拟化才能安装虚拟机 新建虚拟机 鼠标点进去,选中红框所示,回车 登录: 输入默认用户名(超级管理员 root) 密码:安装时设置的密码

  5. Linux基础命令---mirror获取ftp目录

    mirror 使用lftp登录ftp服务器之后,可以使用mirror指令从服务器获取目录   1.语法       mirror [OPTS] [source [target]]   2.选项列表 选 ...

  6. zabbix之被动模式之编译安装proxy

    #:准备源码包,编译安装 root@ubuntu:/usr/local/src# ls zabbix-4.0.12.tar.gz root@ubuntu:/usr/local/src# tar xf ...

  7. Tomcat(2):配置Tomcat

    1,打开IDEA创建一个项目 2,配置Tomcat服务器 3,运行 5,成功 t t

  8. JS - 事件常用

    问:什么是事件? 答:JS创建动态页面,可以被JS侦测到的行为.网页中的每个元素都可以产生某些可以触发JS函数的事件.比如说,当用户点击按钮时,就发生一个鼠标单击(onclick)事件,需要浏览器做出 ...

  9. 【Word】自动化参考文献-交叉引用

    第一步:设置参考文献标号 开始-定义新编号格式中,定义参考文献式的方框编号: 这里注意不要把他原来的数字去掉 第二步:选择交叉引用 插入-交叉引用: 第三步:更新标号 如果更新标号,使用右键-更新域. ...

  10. Windows10常用快捷键+cmd常见命令码

    Windows10常用快捷键+cmd常见命令码 1.Ctrl快捷键 Ctrl+C: 复制 Ctrl+V: 粘贴 Ctrl+A: 全选内容 Ctrl+S: 保存 Ctrl+X: 剪切 Ctrl+Z: 撤 ...