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. JVM1 JVM与Java体系结构

    目录 JVM与Java体系结构 虚拟机与Java虚拟机 虚拟机 Java虚拟机 JVM的位置 JVM的整体结构 Java代码执行流程 JVM的架构模型 基于栈的指令级架构 基于寄存器的指令级架构 两种 ...

  2. adult

    adult是adolescere (grow up)的过去分词. egg - embryo [胚胎] - foetus [就要出生的胎儿] - toddler [刚会走路] - adolescent ...

  3. APK 反编译以及遇到的问题

    APK反编译: https://www.cnblogs.com/geeksongs/p/10864200.html 遇到的问题 https://www.jianshu.com/p/55bf5f688e ...

  4. vue中vuex的五个属性和基本用法

    VueX 是一个专门为 Vue.js 应用设计的状态管理构架,统一管理和维护各个vue组件的可变化状态(你可以理解成 vue 组件里的某些 data ). Vuex有五个核心概念: state, ge ...

  5. SVN终端演练-版本回退

    1. 版本回退概念以及原因?    概念: 是指将代码(本地代码或者服务器代码), 回退到之前记录的某一特定版本    原因: 如果代码做错了, 想返回之前某个状态重做;2. 修改了,但未提交的情况下 ...

  6. 神器Tampermonkey的安装使用

    Tampermonkey是一款基于浏览器的神奇插件,在国内称为油猴,开发者可以在上面开发满足自己需求的各类浏览器应用脚本.不过经过全球各地无数开发者数年的积累现在其官网已经有一大把的优秀的现成脚本,完 ...

  7. Linux上Zookeeper集群搭建

    一.官网 https://zookeeper.apache.org/ 二.下载安装 (1)下载 复制链接地址  http://mirror.bit.edu.cn/apache/zookeeper/zo ...

  8. Spring Batch(0)——控制Step执行流程

    Conditional Flow in Spring Batch I just announced the new Learn Spring course, focused on the fundam ...

  9. 20 个 .NET 6 新增的 API

    DateOnly & TimeOnly .NET 6 引入了两种期待已久的类型 - DateOnly 和 TimeOnly, 它们分别代表DateTime的日期和时间部分. DateOnly ...

  10. dart系列之:浏览器中的舞者,用dart发送HTTP请求

    目录 简介 发送GET请求 发送post请求 更加通用的操作 总结 简介 dart:html包为dart提供了构建浏览器客户端的一些必须的组件,之前我们提到了HTML和DOM的操作,除了这些之外,我们 ...