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+,M=1e6+,inf=1e9+;
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
printf("%I64d\n",(ll)(x/y+)*y);
return ;
}

代码

B. The Same Calendar
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.

The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.

Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).

Input

The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

Output

Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

Examples
input
2016
output
2044
input
2000
output
2028
input
50501
output
50507
Note

Today is Monday, the 13th of June, 2016.

题意:找到这年之后日历相同的年份;

思路:天数整除7并且是同是闰年或平年;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
int check(int x)
{
if((x%==&&x%!=)||x%==)
return ;
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
int ans=;
for(i=x;;i++)
{
ans+=check(i)%;
if(ans%==&&(check(x)==check(i+)))
break;
}
cout<<i+<<endl;
return ;
}

代码

C. Joty and Chocolate
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.

An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.

After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.

Note that she can paint tiles in any order she wants.

Given the required information, find the maximum number of chocolates Joty can get.

Input

The only line contains five integers nabp and q (1 ≤ n, a, b, p, q ≤ 109).

Output

Print the only integer s — the maximum number of chocolates Joty can get.

Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Examples
input
5 2 3 12 15
output
39
input
20 2 3 3 5
output
51

题意:1-n中每个整除a的数可以得到p;1-n中每个整除b的数可以得到q;

    问最多可以得到多少;

思路:简单的容斥;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
ll gcd(ll x,ll y)
{
return y==?x:gcd(y,x%y);
}
int main()
{
int x,y,z,i,t;
ll n,a,b,p,q;
scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
ll aa=n/a;
ll bb=n/b;
ll ans=aa*p+bb*q;
ll lcm=a*b/gcd(a,b);
ans-=n/lcm*min(p,q);
printf("%I64d\n",ans);
return ;
}

代码

D. Iterated Linear Function
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values AB,n and x find the value of g(n)(x) modulo 109 + 7.

Input

The only line contains four integers ABn and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.

Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long longinteger type and in Java you can use long integer type.

Output

Print the only integer s — the value g(n)(x) modulo 109 + 7.

Examples
input
3 4 1 1
output
7
input
3 4 2 1
output
25
input
3 4 3 1
output
79

思路:赤裸裸的矩阵快速幂;

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

代码

Educational Codeforces Round 13 A、B、C、D的更多相关文章

  1. Educational Codeforces Round 88 (Rated for Div. 2) B、New Theatre Square C、Mixing Water

    题目链接:B.New Theatre Square 题意: 你要把所有"." 都变成"*",你可以有两个选择,第一种就是一次铺一个方块(1*1),第二种就是同一 ...

  2. Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维

    题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...

  3. Educational Codeforces Round 45 (Rated for Div. 2) C、D

      C. Bracket Sequences Concatenation Problem time limit per test 2 seconds memory limit per test 256 ...

  4. Educational Codeforces Round 92 (Rated for Div. 2) B、C题解

    TAT 第一场codeforces B. Array Walk #暴力 #贪心 题目链接 题意 有\(a1, a2, ..., an\) 个格子(每个格子有各自分数),最初为1号格(初始分数为\(a1 ...

  5. Educational Codeforces Round 88 (Rated for Div. 2) D、Yet Another Yet Another Task

    题意: 给你一个含n个数a1,a2...an的数组,你要找到一个区间[l,r],使得al+a(l+1)+...+a(r-1)+ar减去max(al,a(l+1),...,a(r-1),ar)的值尽可能 ...

  6. Educational Codeforces Round 13 D:Iterated Linear Function(数论)

    http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  7. Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...

  8. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  9. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

随机推荐

  1. 6.Git代码回滚

    1.代码修改并提交 我们已经成功地添加并提交了一个helloWorld.txt文件,现在,是时候继续工作了. 于是,我们继续修改helloWorld.txt文件,改成如下内容: $ vi helloW ...

  2. servlet实现多文件打包下载

    当用户一次下载多个文件时.普通情况是,每下载一个文件,均要弹出一个下载的对话框.这给用户造成了非常大不便. 比較理想的情况是,用户选择多个文件后.server后端直接将多个文件打包为zip.以下贴出实 ...

  3. 01-开始使用django(全、简)

    目录 (一)创建项目 1.生成django默认目录 2.创建应用目录 3.安装应用 4.配置使用mysql数据库 5.运行轻量级web服务器,预览 (二)设计模型 1.在models.py中定义模型类 ...

  4. Python np.newaxis

    np.newaxis的功能是插入新维度,看下面的例子: a=np.array([1,2,3,4,5])print a.shape print a 输出结果 (5,)[1 2 3 4 5] 可以看出a是 ...

  5. 脚本其实很简单-windows配置核查程序(2)

    bat脚本是什么? 首先讲讲什么是命令行,在windows操作系统中,点击左下角的win图标,直接输入cmd搜索,左键点击进入命令行模式(或按键盘上的win键+r直接调出来命令行窗口). 在windo ...

  6. 机器学习第2周---炼数成金-----线性回归与Logistic

    重点归纳 回归分析就是利用样本(已知数据),产生拟合方程,从而(对未知数据)迚行预测用途:预测,判别合理性例子:利用身高预测体重:利用广告费用预测商品销售额:等等.线性回归分析:一元线性:多元线性:广 ...

  7. 001-搭建spring boot项目

    1.第一步.file--new--project. 2.spring initializr--project sdk--default--next 3. 4.spring boot--选择依赖项--n ...

  8. HTTPS原理解析-转

    这篇文章关于Https的讲解真的是太透彻了,转过来备忘. 来源:腾讯bugly 另附两个SSL/TLS的交互详解:一.二 基于此文章的学习总结:下一篇文章 1.HTTPS 基础 HTTPS(Secur ...

  9. Maven 在 IntelliJ IDEA 中的使用

    一.概述 Maven 为构建软件,与 Gradle 类似,也能以插件的方式在 IntelliJ IDEA 中得到使用. 同样地,你也可以配置环境变量,这样就能够在命令行中进行操作了. 二.使用方式 其 ...

  10. openocd shell脚本

    openocd.sh #! /usr/bin/expectset timeout 30spawn suexpect "密码:"send "123456\r"se ...