Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 ton from left to right. Let's denote a cell of the field on the intersection of row xand column y by record (x, y). Each cell of the field contains growing raspberry, at that, the cell (x, y) of the field contains x + y raspberry bushes.

The bear came out to walk across the field. At the beginning of the walk his speed is (dx, dy). Then the bear spends exactly t seconds on the field. Each second the following takes place:

  • Let's suppose that at the current moment the bear is in cell (x, y).
  • First the bear eats the raspberry from all the bushes he has in the current cell. After the bear eats the raspberry from k bushes, he increases each component of his speed by k. In other words, if before eating the k bushes of raspberry his speed was (dx, dy), then after eating the berry his speed equals(dx + k, dy + k).
  • Let's denote the current speed of the bear (dx, dy) (it was increased after the previous step). Then the bear moves from cell (x, y) to cell (((x + dx - 1) mod n) + 1, ((y + dy - 1) mod n) + 1).
  • Then one additional raspberry bush grows in each cell of the field.

You task is to predict the bear's actions. Find the cell he ends up in if he starts from cell (sx, sy). Assume that each bush has infinitely much raspberry and the bear will never eat all of it.

Input

The first line of the input contains six space-separated integers: nsxsydx,dyt (1 ≤ n ≤ 109; 1 ≤ sx, sy ≤ n;  - 100 ≤ dx, dy ≤ 100; 0 ≤ t ≤ 1018).

Output

Print two integers — the coordinates of the cell the bear will end up in after tseconds.

Example

Input
5 1 2 0 1 2

Output
3 1

Input
1 1 1 -1 -1 2

Output
1 1

Note

Operation a mod b means taking the remainder after dividing a by b. Note that the result of the operation is always non-negative. For example, ( - 1) mod 3 = 2.

In the first sample before the first move the speed vector will equal (3,4) and the bear will get to cell (4,1). Before the second move the speed vector will equal (9,10) and he bear will get to cell (3,1). Don't forget that at the second move, the number of berry bushes increased by 1.

In the second sample before the first move the speed vector will equal (1,1) and the bear will get to cell (1,1). Before the second move, the speed vector will equal (4,4) and the bear will get to cell (1,1). Don't forget that at the second move, the number of berry bushes increased by 1.

123

题意:

n*n的 图  熊初始点在(sx,sy)   速度为 (dx,dy) 每过1 s  都有:

1:速度增加 k    k 为  x+y  ;

2:每个(x,y) 增加 1

3: 熊走的方向   x>>dx +1,  y--> dy +1

根据 关系

我们可以列出:

构造矩阵:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define S1(n)    scanf("%d",&n)
#define SL1(n)   scanf("%I64d",&n)
#define S2(n,m)  scanf("%d%d",&n,&m)
#define SL2(n,m)  scanf("%I64d%I64d",&n,&m)
#define Pr(n)     printf("%d\n",n)using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
int dir[5][2]={0,1,0,-1,1,0,-1,0};const int MAXN=6;
const int N=10;
int mod,sx,sy,dx,dy;
ll t;
struct Matrix{ll arr[N][N];void init(){memset(arr,0,sizeof(arr));for(int i=0;i<MAXN;i++)arr[i][i]=1;//初始化}void iinit(){memset(arr,0,sizeof(arr));arr[0][0]=arr[1][1]=arr[0][5]=arr[1][5]=arr[2][5]=arr[3][5]=2;arr[0][1]=arr[0][2]=arr[0][4]=1;arr[1][0]=arr[1][3]=arr[1][4]=1;arr[2][0]=arr[2][1]=arr[2][2]=arr[2][4]=1;arr[3][0]=arr[3][1]=arr[3][3]=arr[3][4]=1;arr[4][4]=arr[4][5]=1;arr[5][5]=1;}void obj(){memset(arr,0,sizeof(arr));arr[0][0]=sx-1;arr[1][0]=sy-1;arr[2][0]=(dx%mod+mod)%mod;arr[3][0]=(dy%mod+mod)%mod;arr[5][0]=1;}
}A;
Matrix mul(Matrix X,Matrix Y)// 矩阵乘法
{Matrix ans;for(int i=0;i<MAXN;i++)for(int j=0;j<MAXN;j++){ans.arr[i][j]=0;for(int k=0;k<MAXN;k++){ans.arr[i][j]+=X.arr[i][k]*Y.arr[k][j];ans.arr[i][j]%=mod;}}return ans;
}
Matrix Q_pow(Matrix B,ll n)// 矩阵快速幂
{Matrix ans;ans.init();while(n){if(n&1)ans=mul(ans,B);n>>=1;B=mul(B,B);}return ans;
}int main()
{while(~scanf("%d %d %d %d %d %lld",&mod,&sx,&sy,&dx,&dy,&t)){Matrix ans;ans.iinit();ans=Q_pow(ans,t);Matrix FF;FF.obj();FF=mul(ans,FF);printf("%lld %lld\n",FF.arr[0][0]+1,FF.arr[1][0]+1);}return 0;
}

转载于:https://www.cnblogs.com/sizaif/p/9078471.html

Codeforeces Round #226 (Div. 2) E---Bear in the Field(矩阵快速幂)相关推荐

  1. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  2. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  3. Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)

    算一下复杂度.发现可以直接暴.对于u枚举a和b,判断一下是否连边,更新答案. #include<bits/stdc++.h> using namespace std;int n,m; co ...

  4. Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)

    传送门 题目 fn=c2∗n−6fn−1fn−2fn−3\begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{alig ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #257 (Div. 2)

    Codeforces Round #257 (Div. 2) https://codeforces.com/contest/450/ A 模拟 1 #include<bits/stdc++.h& ...

  7. Bear in the Field(CF-385E)

    Problem Description Our bear's forest has a checkered field. The checkered field is an n × n table, ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. linux 空文件 sed 不能写入数据
  2. Scanner 中next()和nexline()方法的区别
  3. 理解linux time命令的输出
  4. 从零开始编写深度学习库(三)ActivationLayer网络层CPU实现
  5. canopy算法流程_Canopy聚类算法
  6. Log4j 日志输出学习(Eclipse)
  7. layuit 框架_UI框架Layui入门介绍
  8. yolov5 简单教程
  9. caffe安装血泪史:caffe不支持cuDNN8
  10. VMware Workstation12安装win 7企业版激活
  11. RFC 5627 SIP中文翻译
  12. google浏览器常用插件整理
  13. 广播与点播、单播与组播
  14. 类和对象(Java)
  15. 校招回忆录---小米篇
  16. gif背景图html,教你更换样式GIF背景图~文末超美!
  17. win10桌面计算机怎么显示器,win10电脑三分屏怎么设置_win10电脑怎么分屏3个显示器...
  18. 2019-2-16-WPF-封装-dotnet-remoting-调用其他进程
  19. Linux系统获取CPU温度
  20. 什么是seo优化?网站seo如何优化

热门文章

  1. opencv AKAZE 局部特征匹配算法
  2. iptables学习笔记:端口转发之“内网访问外网”
  3. JSP和FreeMarker的比较
  4. Spring 配置的项目中数据库链接信息加密(详细)
  5. Linux在线安装Mysql数据库(Linux)
  6. cas登录后怎么直接到我们系统_当我们购买服务器后,那么服务器的操作系统该怎么选择呢?...
  7. 【算法】剑指 Offer 17. 打印从1到最大的n位数
  8. 【Flink】Apache Flink 1.13.0 正式发布,流处理应用更加简单高效
  9. 【分布式ID】理解Snowflake算法的实现原理
  10. 【clickhouse】Error querying database. No buffer space available (maximum connections reached?): conne