2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)
Hypersphere
Time Limit: 1 Second Memory Limit: 32768 KB
In the world of k-dimension, there's a large hypersphere made by mysterious metal. People in the world of k-dimension are performing a ceremony to worship the goddess of dimension. They are melting the large hypersphere into metal flow, and then they will cast the metal flow into unit hyperspheres. An unit hypersphere is a hypersphere which radius is 1.
The mysterious metal in k-dimension world has a miraculous property: if k unit hyperspheres made by the mysterious metal are constructed, all of these k unit hyperspheres will be sacrificed to goddess of dimension and disappear from the k-dimension world immediately.
After the ceremony, there will be some unit hyperspheres and a little metal flow left, and people in the world of k-dimension want to know the number of unit hyperspheres left.
You might want to know that how the large hypersphere was constructed. At first, people in the world created a long ruler which length is l. And then, they drew a rectangle with lengthl - 1 and width l. Using some mysterious method, they changed the rectangle into a square but didn't change the area. After that, they extended the ruler's length by the length of the square's side. After successfully made the ruler, people started using magic to construct the large hypersphere. The magic could make a hypersphere become more and more larger. Started with a hypersphere of zero radius, the magic will be continuously used until the radius reached the ruler's length.
Input
There will be several test cases. Each test case contains two integers k (3 ≤ k ≤ 1000000000) and l (2 ≤ l ≤ 1000000000), which are the same meanings as in the description part.
Output
For each test case, please output the number of unit hyperspheres people will get in one line.
Sample Input
3 3
5 6
Sample Output
2
1
题目大意:意思说的真的很蛋疼,听说跟长沙邀请赛的A题特别像,就看了下。努力让自己淡定下来把题目看完。当时比赛的时候跟吉吉都在忙那个HSL颜色转换的那个模拟题,这个题目根本没注意。当时如果看到这个题目,在读懂的基础上可以直接秒掉。。。题目意思说在一个星球,长度为l,每次进行一次就会变成(l+sqrt(l*(l-1))),每次都会增加,不过小数到最后要舍去,题目中说了单位是1才能算。然后没K个单位会被哪个上帝弄消失。看数据意思就是求[l+sqrt(l*(l-1))]^k%k。
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
long long l,mo;
long long tmp[2][2],p[2][2],ret[2][2]; void init()
{
ret[0][0]=2*l,ret[0][1]=-l,ret[1][0]=1,ret[1][1]=0;
p[0][0]=2*l,p[0][1]=-l,p[1][0]=1,p[1][1]=0;
} void cal1() //矩阵的平方
{
int i,j,k;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
tmp[i][j]=p[i][j];
p[i][j]=0;
}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
for(k=0;k<2;k++)
p[i][j]=(p[i][j]+tmp[i][k]*tmp[k][j])%mo;
} void cal2() //矩阵的乘法
{
int i,j,k;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
tmp[i][j]=ret[i][j];
ret[i][j]=0;
}
for(i=0;i<2;i++)
for(j=0;j<2;j++)
for(k=0;k<2;k++)
ret[i][j]=(ret[i][j]+tmp[i][k]*p[k][j])%mo;
} int main()
{
long long t;
while(~scanf("%lld%lld",&mo,&l))
{
init();
t=mo-1;
while(t)
{
if(t&1) cal2();
cal1();
t>>=1;
}
printf("%lld\n",((ret[1][0]*2*l+ret[1][1]*2)%mo-1+mo)%mo);
}
}
2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)的更多相关文章
- 2013 长沙网络赛J题
思路:这题对于其他能退出所有值的情况比较好像,唯一不能确定的是XXOXXOXXOXX这个形式的序列,其中XX表示未知,O表示已知. 我们令num[1]=0,那么num[4]=sum[3]-sum[2] ...
- 2013 长沙网络赛 B 题 Bizarre Routine
题解 http://blog.csdn.net/u010257508/article/details/11936129 #include <iostream> #include <c ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 2013年省赛H题
2013年省赛H题你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4.想法真的是非常巧妙啊N=100000构造两个数组,f1[N],间隔为Af2[1e4]间隔为A^N,中 ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4751 Divide Groups (2013南京网络赛1004题,判断二分图)
Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- Hive 11、Hive嵌入Python
Hive嵌入Python Python的输入输出都是\t为分隔符,否则会出错,python脚本输入print出规定格式的数据 用法为先add file,使用语法为TRANSFORM (name, it ...
- 《Java程序员面试笔试宝典》之Static关键字有哪些作用
static关键字主要有两种作用:第一,只想为某特定数据类型或对象分配单一的存储空间,而与创建对象的个数无关.第二,希望某个方法或属性与类而不是对象关联在一起,也就是说,在不创建对象的情况下就可以通过 ...
- 【转】使用miniupnpd-->upnp协议 映射本地端口到外网
miniupnpc的主要函数介绍 1>.miniupnpc库主要使用的头文件有 #include"miniwget.h" #include"miniupnpc.h& ...
- 初学github
在公司一直用的SVN做版本管理,倒也没什么问题.最近想自己在家写点东西,上班的时候又想偷偷地写.代码经常在两个地方同步,很是辛苦.反正写的只是一些用来学习测试的代码,干脆放到github上. 1.登录 ...
- ASP.NET MVC 之表格分页
简单效果图:(框架:MVC+NHibernate) 要点: (1)首先建立表格分页Model(GridModel.cs) (2)然后建立数据展示页(PageCloth.cshtml) (3)再建分页版 ...
- [置顶] 【cocos2d-x入门实战】微信飞机大战之十二:分数的本地存储
转载请表明地址:http://blog.csdn.net/jackystudio/article/details/12036237 作为一个单机游戏,连分数存储的的功能都没有,让它怎么在单机游戏圈里混 ...
- Android系统匿名共享内存Ashmem(Anonymous Shared Memory)驱动程序源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6664554 在上一文章Android系统匿名共 ...
- 多线程 AfxBeginThread 与 CreateThread 的区别
简言之: AfxBeginThread是MFC的全局函数,是对CreateThread的封装. CreateThread是Win32 API函数,前者最终要调到后者. 1>.具体说来,Cr ...
- [Python][自己写的杀病毒脚本]
电脑里的HTML都插入了一段VB病毒代码..只能自己手动清除了..发现Python确实好用 import os import re; Root = ["H:"]; for root ...
- 解决ActiveX Control异常:"没有注册类(异常来自 HRESULT:0x80040154(REGDB_E_CLASSNOTREG))"
问题背景: 1.我们的程序是用winform调用unity web player 插件来作为播放器在客户端播放动画文件的. 2.播放器是由我们的客户端程序调用的 3.客户端程序默认是以管理员身份启动的 ...