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. Python与Perl的相似与差别

    Python version 3.7版本 00.命令行交互 命令行交互 Perl Python perl -e <Perl代码>     #Unix/Linux/Windows/DOS 直 ...

  2. Prometheus基础

    监控系统作用 监控系统主要用于保证所有业务系统正常运行, 和业务的瓶颈监控. 需要周期性采集和探测. 采集的详情 采集: 采集器, 被监控端, 监控代理, 应用程序自带仪表盘, 黑盒监控, SNMP. ...

  3. absent, absolute

    absent 1. A teacher asked in a class who killed Abraham Lincoln. A blonde said "It wasn't me, I ...

  4. 浏览器相关,关于强缓存、协商缓存、CDN缓存。

    强缓存和协商缓存 在介绍缓存的时候,我们习惯将缓存分为强缓存和协商缓存两种.两者的主要区别是使用本地缓存的时候,是否需要向服务器验证本地缓存是否依旧有效. 顾名思义,协商缓存,就是需要和服务器进行协商 ...

  5. Linux基础命令---mysqladmin数据库管理工具

    mysqladmin mysqladmin是mysql数据库的管理工具,可以控制.查看.修改数据库服务器的配置和状态. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedor ...

  6. Output of C++ Program | Set 8

    Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...

  7. 类型类 && .class 与 .getClass() 的区别

    一. 什么是类型类 Java 中的每一个类(.java 文件)被编译成 .class 文件的时候,Java虚拟机(JVM)会为这个类生成一个类对象(我们姑且认为就是 .class 文件),这个对象包含 ...

  8. Spring Boot简单操作

    目录 一.自定义异常页面 二.单元测试 ​三.多环境选择 四.读取主配置文件中的属性 五.读取List属性 一.自定义异常页面 对于404.405.500等异常状态,服务器会给出默认的异常页面,而这些 ...

  9. 【C#】【MySQL】C#连接MySQL数据库(二)解析

    C# MySQL 实现简单登录验证 后端代码解析 Visual Studio中使用MySQL的环境配置 下文所有到的代码(前端后端) 请查阅这篇博文 C#连接MySQL数据库(一)代码 获取前端数据 ...

  10. 一行配置搞定 Spring Boot项目的 log4j2 核弹漏洞!

    相信昨天,很多小伙伴都因为Log4j2的史诗级漏洞忙翻了吧? 看到群里还有小伙伴说公司里还特别建了800+人的群在处理... 好在很快就有了缓解措施和解决方案.同时,log4j2官方也是速度影响发布了 ...