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

最新文章

  1. mysql5.6-5.7性能调优
  2. Windows Azure Virtual Machine (27) 使用psping工具,测试Azure VM网络连通性
  3. XMLA连接器--免费但不开源通过ODBO、XMLA
  4. boost库(条件变量)
  5. 自定义异常时如何定义checked异常和unchecked异常
  6. Ch04-文字列表的设计
  7. unity3d KeyCode各键值说明
  8. CentOS7安装Docker时的异常报错与解决方法
  9. VS2013 快捷键 与 RESHARPER 冲突
  10. Mark Russinovich 的博客:Windows Azure 主机更新:原因、时间和方式
  11. java日志框架之logback(一)——logback工程简介
  12. 9、js扩展
  13. Jq_网站顶部定时折叠广告
  14. winform绑定多张图片
  15. Python函数初识
  16. IDEA热部署基于maven的web项目
  17. Python Web学习笔记之为什么设计GIL
  18. BZOJ_3224 Tyvj 1728 普通平衡树 【离散化+权值线段树】
  19. Halcon学习网
  20. zoj 3329 概率dp

热门文章

  1. Microsoft-PetSop4.0(宠物商店)-数据库设计-Oracle
  2. Node.js 使用jQuery取得Nodejs http服务端返回的JSON数组示例
  3. JAVA Eclipse中的Android程序如何使用线程
  4. Win7梦幻桌面字体有问题怎么办
  5. Jscript 随记
  6. odoo分析会计
  7. TCP应用程序通信协议的处理
  8. CentOS 安装rz和sz
  9. MQTT--mosquitto使用详解
  10. mysql临时表空间暴涨