栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3857 Hypersphere

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3857 Hypersphere

#include<cstdio>#include<algorithm>#include<cstring>#include<sstream>#include<iostream>#include<cmath>#include<vector>const int MAXN = 5;typedef long long LL;using namespace std;LL mod = 1;LL l,k;struct matrix{int n,m;LL t[MAXN +10][MAXN +10];void init(){n = 0; m = 0; memset(t,0,sizeof(t));};void init_max(){memset(t,0x3f,sizeof(t));}    void init_e(){init(); for(int i = 0;i < MAXN;i++) t[i][i] = 1;}matrix operator * (matrix a){matrix c;c.init();c.n = n;c.m = a.m;for(int i = 0;i < n;i++)for(int j = 0;j < a.n;j++)for(int k = 0;k < a.m;k++)c.t[i][k] = (c.t[i][k] + t[i][j] * a.t[j][k]) % mod;return c;}};matrix pow(matrix a,int k){matrix ans;ans.init_e();ans.n = a.n;ans.m = a.m;while(k){if(k & 1)ans = ans * a;a = a * a;k >>= 1;}return ans;}int main(){while(cin >> k >> l){mod = k;matrix x,ans;x.init();ans.init();ans.n = 1; ans.m = 2;ans.t[0][0] = 2 % k;ans.t[0][1] = 2*l % k;x.n = x.m = 2;x.t[0][1] = -l;x.t[1][0] = 1; x.t[1][1] = 2*l;ans = ans * pow(x,k);cout << (ans.t[0][0] - 1 + k) % k << endl;}}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371528.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号