现在的位置: 首页 > 综合 > 正文

Codefroces 32C (简单模拟+数学)

2018年04月28日 ⁄ 综合 ⁄ 共 1203字 ⁄ 字号 评论关闭

Description

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 nms (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.

Sample Input

Input
2 3 1000000
Output
6
Input
3 3 2
Output
4

题目大意:题目是说,有一个n*m的棋盘,一只跳蚤,每次只能跳s步,起点可以是棋盘中的任意一个点,跳蚤每次跳过多少个格子,他都能记住,由起点到终点的跳蚤所跳过的格子数记为dxy,那么求出使得dxy最大的起点的个数。

解题思路:

一开始SB了,把这道题的题目理解了好久,总算理解了,其实就是一个简单的数学题了。

# include<cstdio>
# include<iostream>
# include<algorithm>

using namespace std;

int main(void)
{
    long long n,m,s;
    while ( cin>>n>>m )
    {
        cin>>s;
        if ( m>n )
            swap(n,m);
        long long ans = ((n-1)/s+1)*((m-1)/s+1)*((n-1)%s+1)*((m-1)%s+1);
        cout<<ans<<endl;
    }


    return 0;
}

抱歉!评论已关闭.