hdu 3292 No more tricks, Mr Nanguo
No more tricks, Mr Nanguo
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 494 Accepted Submission(s): 334
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.
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).
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”.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll n,k,x,y;
const ll maxn=;
struct matrix
{
ll a[][];
};
void serach(ll n,ll &x,ll &y)
{
y=;
while()
{
x=(1ll)*sqrt(n*y*y+);
if(x*x-n*y*y==) break;
y++;
}
}
matrix mulitply(matrix ans,matrix pos)
{
matrix res;
memset(res.a,,sizeof(res.a));
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
res.a[i][j]+=(ans.a[i][k]*pos.a[k][j])%maxn;
res.a[i][j]%=maxn;
}
}
}
return res;
}
matrix quick_pow(ll m)
{
matrix ans,pos;
for(int i=;i<;i++)
for(int j=;j<;j++)
ans.a[i][j]=(i==j);
pos.a[][]=x%maxn;
pos.a[][]=n*y%maxn;
pos.a[][]=y%maxn;
pos.a[][]=x%maxn;
while(m)
{
if(m&) ans=mulitply(ans,pos);
pos=mulitply(pos,pos);
m>>=;
}
return ans;
}
int main()
{
while(scanf("%lld%lld",&n,&k)!=EOF)
{
ll m=sqrt(n);
if(m*m==n) {printf("No answers can meet such conditions\n");continue;}
serach(n,x,y);
matrix ans=quick_pow(k);
printf("%lld\n",ans.a[][]);
}
return ;
}
hdu 3292 No more tricks, Mr Nanguo的更多相关文章
- 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 ...
- HDU 3292
快速幂模+佩尔方程 #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- hdu3293(pell方程+快速幂)
裸的pell方程. 然后加个快速幂. No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: ...
- 多校3- RGCDQ 分类: 比赛 HDU 2015-07-31 10:50 2人阅读 评论(0) 收藏
RGCDQ Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practic ...
- HDU 3634 City Planning (离散化)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 3624 City Planning(暴力,也可扫描线)
City Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏
D - Painter Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status P ...
- 每日英语:Best Ways to Ramp Up to A Marathon
For the record number of American runners who completed an official race event last year, the questi ...
随机推荐
- Educational Codeforces Round 6 A. Professor GukiZ's Robot 水
A. Professor GukiZ's Robot Professor GukiZ makes a new robot. The robot are in the point with coor ...
- nyoj--18--The Triangle(dp水题)
The Triangle 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...
- HBA卡
HBA,即主机总线适配器英文“Host Bus Adapter”缩写.是一个在服务器和存储装置间提供输入/输出(I/O)处理和物理连接的电路板和/或集成电路适配器. HBA减轻了主处理器在数据存储和检 ...
- java布局管理
FlowLayout :组件在一行中按加入的先后顺序从左至右水平排列,排满后折行,每行中的组件都居中排列.BorderLayout:把容器空间划分为北.南.西.东.中五个区,每加入一个组件都应说明把这 ...
- Re:从0开始的微服务架构:(一)重识微服务架构--转
原文地址:http://www.infoq.com/cn/articles/micro-service-architecture-from-zero?utm_source=infoq&utm_ ...
- C#的常见算法(面试)(转)
一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { ; ...
- Android View 上下左右四种间距的设置方法
RecyclerView控件大家肯定不陌生,已经应用有一段时间了,最近在项目中写一个GridLayout样式的RecyclerView时需要设置,item之间左右的间距,下面是我总结的一个设置间距的方 ...
- js 40 个技巧
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键<table border oncontextmenu= ...
- css让背景颜色与背景图片同时显示
background:url(../images/bg02.png) #25282e left top no-repeat;
- 在远程X server上显示图形的设置方法
1.在服务器的/etc/ssh/sshd_config中,设置X11Forwarding yes,然后重启ssh服务,cd /etc/init.d这个目录下执行 ./ssh restart 2.在客户 ...