Flea

CodeForces - 32C

It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.

The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.

Input

The first line contains three integers n, m, s (1 ≤ n, m, s ≤ 106) — length of the board, width of the board and length of the flea's jump.

Output

Output the only integer — the number of the required starting positions of the flea.

Example

Input
2 3 1000000

Output
6

Input
3 3 2

Output
4

题意:
有n*m的格子块,可以任选格子作为起点,每次只能横着或者竖着跳k个格子。定义d(x,y)为以(x,y)为起点能到达的格子数。
求使得d(x,y)最大的起点共有多少个。

思路:令x = n%s   y = m%s,也就是说行和列用步数整除后分别还剩下几个格子

令z=n/s    t = m/s   ,也就求得用步数平分可以把行列分别分成几段

这样我们只需要任意选取范围内的行列,其交点便是满足的起点,种类数也就是全部乘起来就可以即x*y*z*t

举个例子:加入x = 2,y = 2,z = 3,t = 3,说明行分成了三段还多出两个格子,列也是同样,但是我们如果想要使到达的的格子数最多,我们就不能浪费多出的两个格子,我们发现如果我们我们正向跳跃,0->n,0->m,我们每次取每段的前两个作为起点是不是就成了四段了,而不是三段了,也就是加一,因此我们发现如果余数不为零,我们完全可以让分成的段数加一,只不过每次取的格子是余数的个数,而不是每段格子的个数,这样就可以达到最多。然后相乘也就是,从行选一段从列选一段,然后行列再选格子。

而如果余数是0呢即如果x=0,y=0,z= 3,t=3,那我们就只能从行列每段挑一个,然后在从每段中选一个格子,可选的格子便是每段所包含的格子数,所以我们令x=步数s,y=s,在四个相乘就可以了

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;int main(){ll n,m,s;while(~scanf("%lld%lld%lld",&n,&m,&s)){ll x = n % s;ll y = m % s;ll z = n / s;ll t = m / s;if(x == 0) x = s;else z++;if(y == 0) y = s;else t++;ll ans = x * y * z * t;printf("%lld\n",ans);}return 0;
}

Flea CodeForces - 32C (思维)相关推荐

  1. Codeforce Flea CodeForces - 32C 规律|思维

    题意 给我们一个n*m的表格 告诉我们每次跳跃的格子数量s 只能垂直或者水平跳跃 可以跳跃无限次 那么某格子能到达的不同格子的数量就是这个格子的值 求表格中值最大的格子的数量 分析 表面上看像是搜索 ...

  2. CodeForces 798D 思维,贪心

    CodeForces 798D 题意:长度为 n的两个数组 a[]和 b[],要找出 k ( k<=n/2+1 )个下标,使得在两个数组中这 k个数的和乘上 2 要大于所有数的和. tags: ...

  3. codeforces - 1315C - 思维题

    原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...

  4. Balanced Substring CodeForces - 873B (思维+前缀和)

    Balanced Substring CodeForces - 873B You are given a string s consisting only of characters 0 and 1. ...

  5. Codeforces 1093C (思维+贪心)

    题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...

  6. B. Bogosort codeforces(思维)

    outputstandard output You are given an array a1,a2,-,an. Array is good if for each pair of indexes i ...

  7. Count Subrectangles CodeForces - 1323B(思维)

    You are given an array a of length n and array b of length m both consisting of only integers 0 and ...

  8. Dead Pixel CodeForces - 1315A(思维)

    Screen resolution of Polycarp's monitor is a×b pixels. Unfortunately, there is one dead pixel at his ...

  9. Three Integers CodeForces - 1311D(思维+暴力)

    You are given three integers a≤b≤c. In one move, you can add +1 or −1 to any of these integers (i.e. ...

  10. Interesting Array CodeForces - 483D(思维+线段树)

    We'll call an array of n non-negative integers a[1], a[2], -, a[n] interesting, if it meets m constr ...

最新文章

  1. mips 内存 linux,MIPS 在linux中的内存映射
  2. 在国外读phd 的时候和supervisor沟通的时候需要注意的点
  3. 第4章 Python 数字图像处理(DIP) - 频率域滤波1 - 傅里叶级数和变换简史
  4. 这篇顶会paper,讲述了疫情期间憋疯的你和我
  5. KMP字符串比对算法理解
  6. 必知必会SQL(贰) --索引(聚集[簇]索引和非聚[簇]集索引) vs 全文本索引
  7. 前苹果员工创办激光雷达公司,获4500万美元融资,曾参与苹果机密项目
  8. VALSE学习(一):high-resolution representation learning-高分辨率表示学习-姿态估计
  9. TI DSP 28335 自学之路,到此止步
  10. 字节跳动拒招33岁程序员,网友:这也太坑了!太不合理!
  11. 百思不得其姐学习笔记
  12. 服装行业ERP选型咨询提纲
  13. 杀戮空间2服务器协议,杀戮空间2服务器设置
  14. java版溺尸刷怪塔_教程/溺尸陷阱 _ 《我的世界》中文Minecraft Wiki:最详细的官方我的世界百科...
  15. markdownpad2使用
  16. 浅谈 Java 中的排序
  17. 365天挑战LeetCode1000题——Day 116 第315场周赛 「中国银联 力扣」
  18. i.MX arm 3.12.28 Kernel Configuration
  19. 产品部和业务部门的利益之争
  20. linux fuser主机关闭,linux 下强制umount+Fuser命令详解

热门文章

  1. 怎样设定目标(三)—— 目标设定前的准备
  2. java-老鼠出迷宫
  3. Redis连接报错【redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password 】
  4. 谈谈“五级工程师和职业发展”的思考
  5. HTML常用的颜色代码参考表|前端使用颜色必备
  6. svg 地图 及path的渲染
  7. 赛码网笔试Java代码示例
  8. 房屋水电煤气省钱秘籍
  9. t450加固态硬盘教程_T450能加固态硬盘么 是什么接口
  10. vue-element-admin 框架结构粗解