HNU 11720 God Created The Integers
原题传送:http://acm.hnu.cn/online/?action=problem&type=show&id=11720&courseid=0
对于这条式子:
和下面的式子是等价的:
Sp = (p2 - 1) / 2 - (p - 1) / 4
那么求出Sp后有rp*Sp ≡ 1 (mod p),用扩展GCD求出rp就行了。
1 #include <stdio.h> 2 #include <string.h> 3 4 typedef __int64 LL; 5 LL p, s; 6 7 LL exgcd(LL a, LL b, LL &x, LL &y) 8 { 9 LL d, t; 10 if(b == 0) 11 { 12 x = 1, y = 0; 13 return a; 14 } 15 d = exgcd(b, a % b, x, y); 16 t = x, x = y, y = t - (a / b) * x; 17 return d; 18 } 19 20 void solve(int cas) 21 { 22 s =(p * p - 1) / 24 - (p - 1) / 4; 23 LL x, y; 24 exgcd(s, p, x, y); 25 printf("Case #%d: %I64d\n", cas, (x + p) % p); 26 } 27 28 int main() 29 { 30 int t, cas; 31 while(scanf("%d", &t) != EOF) 32 { 33 for(cas = 1; cas <= t; cas ++) 34 { 35 scanf("%I64d", &p); 36 solve(cas); 37 } 38 } 39 return 0; 40 }
转载于:https://www.cnblogs.com/huangfeihome/archive/2012/10/06/2713070.html
HNU 11720 God Created The Integers相关推荐
- 代数一千二百年:花拉子米和智慧宫 ︱ 尼克
花拉子米 (780-850) 文︱尼 克 波斯大学问家花拉子米在巴格达把他那本教人求解一元二次方程的书用裹尸布包好,题献给有波斯血统的阿巴斯王朝哈里发马蒙.这标志着代数的诞生,是人类文明史上最重要的 ...
- vue.js created函数注意事项
因为created钩子函数是页面一加载完就会调用的函数,所以如果你想在这个组件拿值或者是赋值,很可能this里面能拿到数据,但是如果你用this.赋值的话,控制台或者debugger都会发现this里 ...
- 求逆元 - HNU 13412 Cookie Counter
Cookie Counter Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13412& ...
- cmake, This may result in binaries being created in the wrong place
现象: CMake Error: The current CMakeCache.txt directory /home/etouch/minigui-64/minigui/libmgeff-1.0.0 ...
- 关于Vue实例的生命周期created和mounted的区别
关于作者 程序开发人员,不拘泥于语言与技术,目前主要从事PHP和前端开发,使用Laravel和VueJs,App端使用Apicloud混合式开发.合适和够用是最完美的追求. 个人网站:http://w ...
- Upgrade after a crash is not supported. The redo log was created with Maria的解决办法
关于[InnoDB] Unsupported redo log format (0). The redo log was created before MySQL 5.7.9的解决办法 利用mkdir ...
- Selenium 爬虫时遇到的问题 Selenium message:session not created
出现问题如下: Selenium message:session not created: This version of ChromeDriver only supports Chrome vers ...
- vue component created没有触发_Vue的难点解析
watch 和 computed 和 methods 区别是什么? computed 计算属性,在模板中双向绑定一些数据或表达式时,如果表达式过长,或逻辑更为复杂,就会变得臃肿,难以维护和阅读 < ...
- pandas将dataframe原有的数据列名称转化为整数数值列名称(convert dataframe column labelsl into integers)
pandas将dataframe原有的数据列名称转化为整数数值列名称(convert dataframe column labelsl into integers) 目录 pandas将datafra ...
最新文章
- 用好idea这几款插件,可以帮你少写30%的代码!
- oracle:ORA-01940无法删除当前已连接用户的解决方案
- C#把某个数组的一部分复制到另一个数组中的两种方法:Buffer.BlockCopy和Array.Copy...
- Git客户端(TortoiseGit)基本使用详解
- just for rest~
- c语言socket面试题,【C++工程师面试宝典】学习说明_互联网校招面试真题面经汇总_牛客网...
- C#.NET学习笔记7--11---算术运算符,变量赋值,变量的交换,布尔表达式1,布尔表达式2
- iOS App常用的宏
- 矩阵分析之 实矩阵分解(3)Cholesky分解
- k-近邻算法的优缺点及拓展思考
- SRCNN:Image Super-Resolution Using Deep Convolutional Networks
- C语言——宏定义及保留n位小数
- 计算机网络的时间,计算机网络时间同步技术原理介绍
- php循环实现金字塔,PHP中使用循环实现的金字塔图形
- 骑行运动,对青春期年青人有什么好处?
- 十字军之王3Crusader Kings III mac中文
- c语言程序设计 doc,C语言程序设计精彩资料100例.doc
- 迅雷和FlashGet 地址转换工具_6617.com
- U盘怎么量产 怎么对U盘进行量产
- 导入MVVMLight出现错误 ViewModelLocator does not exist in the namespace clr-namespace:WpfApp1.ViewModel
热门文章
- 『设计模式』工厂方法模式
- 疯子的算法总结11--次小生成树+严格次小生成树
- springboot 之 webscoket 服务端推送
- Verilg 2001相对于Verilog 1995的改进(Z) (内含 乘方 运算符** )
- python3(六)监督学习
- 深度学习领域专业词汇_深度学习时代的人文领域专业知识
- nlp文本相似度_用几行代码在Python中搜索相似文本:一个NLP项目
- SRX alarm: Autorecovery information needs to be saved
- java set contains用法,Java TreeSet contains()用法及代码示例
- 如何将另外一个表里的数据与联动_跨境电商(亚马逊)后台财务数据包