hdu3293(pell方程+快速幂)
裸的pell方程。 然后加个快速幂.
No more tricks, Mr Nanguo
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 320 Accepted Submission(s): 207
In the period of the Warring States (475-221 BC), there was a state called Qi. The king of Qi was so fond of the yu, a wind instrument, that he had a band of many musicians play for him every afternoon. The number of musicians is just a square number.Beacuse a square formation is very good-looking.Each row and each column have X musicians.
The king was most satisfied with the band and the harmonies they performed. Little did the king know that a member of the band, Nan Guo, was not even a musician. In fact, Nan Guo knew nothing about the yu. But he somehow managed to pass himself off as a yu player by sitting right at the back, pretending to play the instrument. The king was none the wiser. But Nan Guo's charade came to an end when the king's son succeeded him. The new king, unlike his father, he decided to divide the musicians of band into some equal small parts. He also wants the number of each part is square number. Of course, Nan Guo soon realized his foolish would expose, and he found himself without a band to hide in anymore.So he run away soon.
After he leave,the number of band is Satisfactory. Because the number of band now would be divided into some equal parts,and the number of each part is also a square number.Each row and each column all have Y musicians.
3 1000001
4 8373
600
No answers can meet such conditions
//
// main.cpp
// hdu3292
//
// Created by 陈加寿 on 15/12/1.
// Copyright (c) 2015年 陈加寿. All rights reserved.
// #include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std; #define MOD 8191 void matrix_mul(long long s[][],long long t[][])
{
long long tmp[][];
memset(tmp,,sizeof(tmp));
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
tmp[i][j]=(tmp[i][j]+s[i][k]*t[k][j])%MOD;
for(int i=;i<;i++)
for(int j=;j<;j++)
s[i][j]=tmp[i][j];
} int main(int argc, const char * argv[]) {
long long n,k;
while(cin>>n>>k)
{
long long x=sqrt( (double)n );
if(x*x==n)
{
printf("No answers can meet such conditions\n");
continue;
}
//然后开始寻找第一个解
long long x0,y0;
for(long long i=;;i++)
{
x=sqrt((double)(i*i*n+));
if(x*x==i*i*n+)
{
x0=x;
y0=i;
break;
}
}
long long mat[][],ans[][];
mat[][]=x0; mat[][]=y0;
mat[][]=n*y0; mat[][]=x0;
memset(ans,,sizeof(ans));
ans[][]=; ans[][]=;
k-=;
while(k)
{
if(k&) matrix_mul(ans,mat);
k>>=;
matrix_mul(mat,mat);
}
long long ans1;
ans1 = (x0*ans[][]+y0*ans[][])%MOD;
cout<<ans1<<endl;
}
return ;
}
hdu3293(pell方程+快速幂)的更多相关文章
- No more tricks, Mr Nanguo HDU - 3292(pell + 矩阵快速幂)
No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Jav ...
- HDU 3292 【佩尔方程求解 && 矩阵快速幂】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...
- hdu3483 A Very Simple Problem 非线性递推方程2 矩阵快速幂
题目传送门 题目描述:给出n,x,mod.求s[n]. s[n]=s[n-1]+(x^n)*(n^x)%mod; 思路:这道题是hdu5950的进阶版.大家可以看这篇博客hdu5950题解. 由于n很 ...
- Pell方程及其一般形式
一.Pell方程 形如x^2-dy^2=1的不定方程叫做Pell方程,其中d为正整数,则易得当d是完全平方数的时候这方程无正整数解,所以下面讨论d不是完全平方数的情况. 设Pell方程的最小正整数解为 ...
- POJ 1320 Street Numbers Pell方程
http://poj.org/problem?id=1320 题意很简单,有序列 1,2,3...(a-1),a,(a+1)...b 要使以a为分界的 前缀和 和 后缀和 相等 求a,b 因为序列很 ...
- HDU 4471 矩阵快速幂 Homework
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写 ...
- bzoj 2242: [SDOI2011]计算器 BSGS+快速幂+扩展欧几里德
2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description 你被 ...
- CodeForces 185A 快速幂
一开始找矩阵快速幂的题来做时就看到了这题,题意就是让你求出如图所示的第n个三角形中指向向上的小三角形个数.从图中已经很容易看出递推关系了,我们以f[n]表示第n个大三角形中upward的小三角形个数, ...
- [HDOJ2604]Queuing(递推,矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 递推式是百度的,主要是练习一下如何使用矩阵快速幂优化. 递推式:f(n)=f(n-1)+f(n- ...
随机推荐
- kubernetes1.5.2--部署DNS服务
本文基于kubernetes 1.5.2版本编写 在kubernetes1.2之前,采用skydns+kube2dns+etcd的方式来部署dns.而从1.3开始,则部署方式有了一点儿变化,将skyd ...
- Chrome的Waterfall
参考: 1.https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#timing 2 ...
- AJAX enabled & disabled
@model string @{ ViewBag.Title = "GetPeople"; AjaxOptions ajaxOpts = new A ...
- squid 三种代理实验
squid 软件既可以做代理,也可以做实现缓存加速,大大降低服务器的I/O.. 1.其中squid代理分为三种,正向代理.透明代理.反向代理. (1)squid正向代理和squid透明代理都位客户端: ...
- 工具分享:GitHub的克隆工具Cl0neMast3r,轻松搞定各种测试
GitHub,相信大家并不陌生,咱搞技术的应该都会用到它,GitHub主要是进行代码工具的存储.下载等工作.今天介绍一款让我们操作GitHub相关工作变的更简单的工具, GitHub的克隆工具. Cl ...
- ISP模块之彩色图像增强--ACE算法 .
ACE(Automatic Color Enhancement),自动色彩增强算法,是一种对于彩色图像增强十分行之有效的方法.它的改进算法以及快速实现在文章Automatic Color Enhanc ...
- 新装系统(CentOS7.4)环境初始化配置笔记
新装系统(CentOS7.4)环境初始化配置笔记 一.概述 设备详情: Dell R730 服务器 (四个网卡,一根网线插在第2个网卡上) CentOS 7.4 x64 最小安装环境 二.网络环境配置 ...
- 利用fpm定制rpm包
环境说明 系统版本 CentOS 6.9 x86_64 软件版本 fpm-1.4.0 1.安装ruby环境 fpm利用ruby编程语言开发,先安装ruby的环境 [root@m01 ~]# ...
- XP中如何配置和共享打印机
Win XP中如何配置和共享打印机 一.配置 打印机 在"控制面板"打开"打印机和传真",在左边的选项或单击右键选择" ...
- ACdreamoj 1011(树状数组维护字符串hash前缀和)
题目链接:http://acdream.info/problem? pid=1019 题意:两种操作,第一种将字符串某个位置的字符换为还有一个字符.另外一种查询某个连续子序列是否是回文串: 解法:有两 ...