uva10294 Arif in Dhaka (First Love Part 2)

137 篇文章 0 订阅

Our hero Arif is now in Dhaka (Look at problem 10244 { First Love if
you want to know more about Arif, but that information is not
necessary for this problem. In short, Arif is a brilliant programmer
working at IBM ) and he is looking for his rst love. Days pass by but
his destiny theory is not working anymore, which means that he is yet
to meet his rst love. He then decides to roam around Dhaka on a
rickshaw (A slow vehicle pulled by human power), running DFS (by
physical movement) and BFS (with his eyes) on every corner of the
street and market places to increase his probability of reaching his
goal. While roaming around Dhaka he discovers an interesting necklace
shop. There he nds some interesting necklace/bracelet construction
sets. He decides to buy some of them, but his programmer mind starts
looking for other problems. He wants to nd out how many different
necklace/bracelet can be made with a certain construction set. You are
requested to help him again. The following things are true for a
necklace/bracelet construction set. a) All necklace/bracelet
construction sets has a frame, which has N slots to place N beads. b)
All the slots must be lled to make a necklace/bracelet . c) There are
t types of beads in a set. N beads of each type are there in the box.
So the total number of beads is t N ( t multiplied by N ), of which
exactly N can be used at a time. Fig. 1: Different types of necklace
for t
= 2 and different value of N The gure above shows necklaces for some different values of N (Here, t is always 2). Now let’s turn out
attentions to bracelets . A bracelet is a necklace that can be turned
over (A junior programmer in Bangladesh says that wrist watch is a
necklace (Boys!!! Don’t mind :-)) ). So for a bracelet the following
two arrangements are equivalent. Similarly, all other opposite
orientation or mirror images are equivalent. So, given the description
of a necklace/bracelet construction set you will have to determine how
many different necklace and bracelet can be formed with made with that
set Input The input le contains several lines of input. Each line
contains two positive integers N (0 < N< 51) and t (0 < t< 11) as
described in the problem statement. Also note that within this input
range inputs will be such that no nal result will exceed 11 digits.
Input is terminated by end of le. Output For each line of input
produce one line of output which contains two round numbers NN and NB
separated by a single space, where NN is the number of total possible
necklaces and NB is the number of total possible bracelets for the
corresponding input set.

将“不变”的变换认为是旋转 0 次。
如果旋转i(0i<n)次,那么“不动点”个数为 tgcd(i,n)
对于对称,共有 n 条对称轴,也就是n种变换。当 n 为奇数,有nt(n+1)/2个不动点,当 n 为偶数,有n2tn/2+n2tn/2+1个不动点。
最后求平均值。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL pow[55];
int gcd(int x,int y)
{
    if (!y) return x;
    return gcd(y,x%y);
}
int main()
{
    int n,m,i;
    LL ans;
    while (scanf("%d%d",&n,&m)==2)
    {
        pow[0]=1;
        for (i=1;i<=n;i++)
            pow[i]=pow[i-1]*m;
        ans=0;
        for (i=0;i<n;i++)
            ans+=pow[gcd(i,n)];
        printf("%lld ",ans/n);
        if (n&1) ans+=pow[(n+1)/2]*n;
        else ans+=pow[n/2]*n/2+pow[n/2+1]*n/2;
        printf("%lld\n",ans/n/2);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值