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- ...
随机推荐
- django模板解析 循环列表中 切片和求长度
{% for subrow in subdic.content|slice:":5" %} {% endfor %} {% if "{{subdic.content|le ...
- MySql中LongText字段对应Hibernate映射文件的设置(转)
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hi ...
- 使用Ant构建简单项目
Apache Ant主要用于Java项目的构建.为什么要使用Ant: 1)项目构建不是简单的编译,各种资源需要合理构建,例如有的类需要压缩成jar文件,有的文件需要放在指定位置,有时候需要使用配置文件 ...
- ios网络学习------10 原生API文件上传
使用原生态的api上传文件的实现: #import "MainViewController.h" @interface MainViewController () @propert ...
- (通用Mapper、分页,批量插入,一分钟接入)spring mvc+mybatis+maven集成tkmapper+pagehelper
<!-- maven tkmapper引入--> <dependency> <groupId>tk.mybatis</groupId> <arti ...
- Oracle 时间 MM-dd形式转换
SELECT TO_CHAR( SYSDATE,'MM-dd') AS beginTime,TO_CHAR( TO_DATE(MAX(C.SUBSCRIBE_DATE),'YYYY-MM-dd'),' ...
- (九)Thymeleaf用法——Themeleaf注释
4. 注释 模板名称:comment.html 4.1 标准 HTML/XML注释 语法:<!-- --> 4.2 解析器级注释块(Parser-level ...
- block知识点
1.block引用局部变量的时候,该变量会作为常量编码到block中,在block中不能被修改. 2.使用 __block修饰的局部变量,不会作为常量被编码到block中,故而在block中可以被修改 ...
- js 元素Dom新建并插入页面createElement
纯js var o = document.createElement('script'); o.type = 'text/template'; o.id = 'demo'; document.docu ...
- 初识C++之虚函数
1.什么是虚函数 在基类中用virtual关键字修饰.并在一个或多个派生类中被又一次定义的成员函数.使用方法格式为: virtual 函数返回类型 函数名(參数表) { 函数体 } 虚函数是实现多态性 ...