2013長沙網路賽H題Hypersphere (蛋疼的題目 神似邀請賽A題)
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
#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長沙網路賽 E題(水題 有點小bug)
- 第三屆華中地區邀請賽網路賽題解
- NJUST 1746 Similar Number(南京邀請賽 J題)MILA
- 【構造共軛函式+矩陣快速冪】HDU 4565 So Easy! (2013 長沙賽區邀請賽)函式矩陣
- 2024ICPC 武漢邀請賽題解 更新至 8 題
- 2013成都網路賽 兩個簡單題
- HDU 4496D-City2013通化邀請賽D題(並查集 需要壓縮路徑)並查集
- 2013杭州網路賽C題HDU 4640(模擬)
- 2013成都網路賽1004題HDU 4731Minimum palindrome (思維題目)
- 2024ICPC武漢邀請賽E. Boomerang 題解OOM
- 【題目全解】ACGO排位賽#9Go
- 【題目全解】ACGO排位賽#13Go
- 【題目全解】ACGO排位賽#12Go
- 2018天梯賽、藍橋杯、(CCPC省賽、邀請賽、ICPC邀請賽)校內選拔賽反思總結!
- 2024ccpc網路賽補題
- 【題目全解】ACGO挑戰賽#8Go
- 2018 徐州網路賽 G 題解
- 素養賽Python複賽題——錯排問題Python
- [題解] [CCPC陝西省賽2022 H題] Cute Rabbit
- 賽題要點
- hdu5445 || 2015長春網路賽1009題 多重揹包問題
- 高校戰“疫”網路安全分享賽-部分PWN題-wp
- 藍橋杯競賽題目:”機器人繁殖“解析及題解機器人
- Task 1 賽題理解
- CCTF部分賽題分析
- Google賽馬問題Go
- 模擬賽雜題
- [比賽總結]青島理工大學邀請賽比賽總結
- HDU4592 Boring Game (2013 ACM-ICPC南京賽區全國邀請賽) 高斯消元GAMACM
- 第八屆“網際網路+”大賽 | 雲原生賽道邀你來挑戰
- hdu5452 || 瀋陽網路賽1003題 最近公共祖先問題
- BOT大賽計算機視覺賽題經驗分享:賽題詳解與思路分析計算機視覺
- 題目分享H 二代目
- 2024ICPC網路賽第一場題解(部分)
- 猿人學web端爬蟲攻防大賽賽題第19題——烏拉烏拉烏拉Web爬蟲
- 猿人學web端爬蟲攻防大賽賽題第6題——js 混淆 - 回溯Web爬蟲JS
- 2024ccpc濟南邀請賽
- “網際網路+”大學生創新創業大賽來了,歡迎報名龍蜥社群賽題!創業