您的位置:首页 > 其它

Educational Codeforces Round 13 A、B、C、D

2016-06-21 15:40 344 查看
A. Johny Likes Numbers

time limit per test
0.5 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.

Input
The only line contains two integers n and k (1 ≤ n, k ≤ 109).

Output
Print the smallest integer x > n, so it is divisible by the number k.

Examples

input
5 3


output
6


input
25 13


output
26


input
26 13


output
39
题意:找到一个大于n并且被k整除的最小的数;
思路:除+1;


#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+10,M=1e6+10,inf=1e9+10;
struct is
{
ll a[10][10];
};
ll x,m,k,c;
is juzhenmul(is a,is b,ll hang ,ll lie)
{
int i,t,j;
is ans;
memset(ans.a,0,sizeof(ans.a));
for(i=1;i<=hang;i++)
for(t=1;t<=lie;t++)
for(j=1;j<=lie;j++)
{
ans.a[i][t]+=(a.a[i][j]*b.a[j][t]);
ans.a[i][t]%=mod;
}
return ans;
}
is quickpow(is ans,is a,ll x)
{
while(x)
{
if(x&1)  ans=juzhenmul(ans,a,2,2);
a=juzhenmul(a,a,2,2);
x>>=1;
}
return ans;
}
int main()
{
int y,z,i,t;
ll a,b,n,x;
scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&x);
is base;
base.a[1][1]=a;
base.a[1][2]=0;
base.a[2][1]=b;
base.a[2][2]=1;
is ans;
memset(ans.a,0,sizeof(ans.a));
ans.a[1][1]=1;
ans.a[2][2]=1;
ans=quickpow(ans,base,n);
printf("%I64d\n",(x*ans.a[1][1]+ans.a[2][1])%mod);
return 0;
}


代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: