Buildings Gym - 101873B

在Colorville,每个房屋都是一道独特的风景线,由n×n颜色方块构成的多边形墙壁与统一的屋顶色彩共同编织出小镇的多彩风貌。Alan面临的选择难题:如何在有限的颜色和设计规则下,计算出所有可能的房屋设计组合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a different place. However, this newest town is his favorite yet - it is just so colorful. Alan has recently moved to Colorville, a smallish city in between some really nice mountains. Here, Alan has finally decided to settle down and build himself a home - a nice big house to call his own. In Colorville, many people have their own houses - each painted with a distinct pattern of colors such that no two houses look the same. Every wall consists of exactly n × n squares, each painted with a given color (windows and doors are also seen as unique “colors”). The walls of the houses are arranged in the shape of a regular m-gon, with a roof on top. According to the deep traditions of Colorville, the roofs should show the unity among Colorvillians, so all roofs in Colorville have the same color. Figure B.1: Example house design for n = 3, m = 6. Of course, Alan wants to follow this custom to make sure he fits right in. However, there are so many possible designs to choose from. Can you tell Alan how many possible house designs there are? (Two house designs are obviously the same if they can be translated into each other just by rotation.)

Input

The input consists of: • one line with three integers n, m, and c, where – n (1 ≤ n ≤ 500) is the side length of every wall, i.e. every wall consists of n × n squares; – m (3 ≤ m ≤ 500) is the number of corners of the regular polygon; – c (1 ≤ c ≤ 500) the number of different colors. GCPC 2017 Problem B: Buildings 3

Output

Output s where s is the number of possible different house designs. Since s can be very large, output s mod (109 + 7).

Sample Input 1

1  3  1

Sample Output 1

1

Sample Input 2

2 5 2

Sample Output 2

 209728

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll pow_mod(ll x,ll n)
{
    ll ans = 1;
    while(n)
    {
        if(n%2==1)
        {
            ans *= x;
            ans %= mod;
        }
        n /= 2;
        x *= x;
        x %= mod;
    }
    return ans;
}
int main()
{
    ll n,m,c,i,ans = 0,x;
    scanf("%lld%lld%lld",&n,&m,&c);

    for(i=0;i<m;i++)
    {
        x = __gcd(i,m);
        ans += pow_mod(c,n*n*x);
        ans %= mod;
    }
    ans = ans * pow_mod(m,mod-2)%mod;
    printf("%lld\n",ans);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值