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
output
input
output
input
output
代码
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; }
代码
相关文章推荐
- reactjs的一些笔记
- 准备把平台挪到linux
- python deep copy and shallow copy
- 第十二周项目三数组类运算的实现
- C#使用Microsoft.Office.Interop.Excel.dll读取Excel文件
- mysql 复制
- 辩数字
- android listview的优化
- short运算关于"="与"+=";
- leetcode 23. Merge k Sorted Lists
- Eclipse代码导入到AndroidStudio的两种方式
- mysql性能优化之swap占用高
- mysql 语句
- iOS开发之第三方登录微博-- 史上最全最新第三方登录微博方式实现
- POJ 1236 Network of Schools (有向图的强连通分量)
- JS中如何使用radio
- 后台数据库的增删改查 项目的
- C 碎片七 指针
- mysql binlog 数据介绍
- leetcode 24. Swap Nodes in Pairs