裸的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

Problem Description
Now Sailormoon girls want to tell you a ancient idiom story named “be there just to make up the number”. The story can be described by the following words.
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.
 
Input
There are multiple test cases. Each case contains a positive integer N ( 2 <= N < 29). It means the band was divided into N equal parts. The folloing number is also a positive integer K ( K < 10^9).
 
Output
There may have many positive integers X,Y can meet such conditions.But you should calculate the Kth smaller answer of X. The Kth smaller answer means there are K – 1 answers are smaller than them. Beacuse the answer may be very large.So print the value of X % 8191.If there is no answers can meet such conditions,print “No answers can meet such conditions”.
 
Sample Input
2 999888
3 1000001
4 8373
 
Sample Output
7181
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方程+快速幂)的更多相关文章

  1. 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 ...

  2. HDU 3292 【佩尔方程求解 && 矩阵快速幂】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...

  3. hdu3483 A Very Simple Problem 非线性递推方程2 矩阵快速幂

    题目传送门 题目描述:给出n,x,mod.求s[n]. s[n]=s[n-1]+(x^n)*(n^x)%mod; 思路:这道题是hdu5950的进阶版.大家可以看这篇博客hdu5950题解. 由于n很 ...

  4. Pell方程及其一般形式

    一.Pell方程 形如x^2-dy^2=1的不定方程叫做Pell方程,其中d为正整数,则易得当d是完全平方数的时候这方程无正整数解,所以下面讨论d不是完全平方数的情况. 设Pell方程的最小正整数解为 ...

  5. POJ 1320 Street Numbers Pell方程

    http://poj.org/problem?id=1320 题意很简单,有序列 1,2,3...(a-1),a,(a+1)...b  要使以a为分界的 前缀和 和 后缀和 相等 求a,b 因为序列很 ...

  6. HDU 4471 矩阵快速幂 Homework

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写 ...

  7. bzoj 2242: [SDOI2011]计算器 BSGS+快速幂+扩展欧几里德

    2242: [SDOI2011]计算器 Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 你被 ...

  8. CodeForces 185A 快速幂

    一开始找矩阵快速幂的题来做时就看到了这题,题意就是让你求出如图所示的第n个三角形中指向向上的小三角形个数.从图中已经很容易看出递推关系了,我们以f[n]表示第n个大三角形中upward的小三角形个数, ...

  9. [HDOJ2604]Queuing(递推,矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 递推式是百度的,主要是练习一下如何使用矩阵快速幂优化. 递推式:f(n)=f(n-1)+f(n- ...

随机推荐

  1. hdoj 1159最长公共子序列

     /*Common Subsequence A subsequence of a given sequence is the given sequence with some elements ( ...

  2. #if 条件编译

    1.格式: #if constant-expression statements #elif constant-expression statements #else statements #endi ...

  3. python实现将文件夹内所有txt文件合并成一个文件

    新建一个文件夹命名为yuliao,把所有txt文件放进去就ok啦!注意路径中‘/’,windows下路径不是这样. #coding=utf-8  import os #获取目标文件夹的路径 filed ...

  4. Python Requests post并将得到结果转换为json

    Python Requests post并将得到结果转换为json 学习了:https://blog.csdn.net/sinat_28680819/article/details/70940325  ...

  5. HDU 2767 Proving Equivalences (强联通)

    pid=2767">http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 40 ...

  6. FizzBuzz and Fibonacci优化

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  7. 单一按钮显示/隐藏&&提示框效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Linux 常见安全检查方法

    Linux 常见安全检查方法进行概要说明: 一.检查系统密码文件,查看文件修改日期 # ls -l /etc/passwd 二.查看 passwd 文件中有哪些特权用户 # awk -F: '$3= ...

  9. vscode - 添加背景图片

    首先,Ctrl+Shift+P安装backround , 而后重启vscode会有默认的背景图片 修改背景图,可自定义三张 具体请看gif图 最开始时,发现png根本不是全透明,用ps处理了一下(下列 ...

  10. 第14章5节《MonkeyRunner源代码剖析》 HierarchyViewer实现原理-装备ViewServer-查询ViewServer执行状态

    上一小节我们描写叙述了HierarchyViewer是怎样组建ADB协议命令来实现ViewServer的port转发的.在port转发设置好后,下一个要做的事情就是去检測目标设备端ViewServer ...