17.07.22 ICPCECIC Problem E

Problem: E

Problem Description

When he was a little boy, Jieba had always been interested in geometry.  One time, he got many pieces of colored square cards. For each color, he had as many pieces as he wanted. At that time, he decided to make some cubes using these cards. He wanted to know how many kinds of cubes could he make? (if one kind of cube can rotate to another kind, they will be seen the same)

Input

Every line of the input file defines a test case and contains one integer: the number of available colors n (0<n<1000)

 

Output

For each test case output on a single line the number of different kinds of cubes. Because the result may be too large, please mod the result with 1000000007.

 

Sample Input
1
2

Sample Output
1
10

_______________________

好久没写题了……真是怠惰啊

题意:用n种颜色给正方体上色,若正方体旋转后相同则视为一种情况,问有多少种正方体。(颜色可重复使用)
看到题愣了一下……一看就是个很难的数学题,以前写的类似的题都是2种或4种颜色的,现在干脆给个n……
没有办法只好去网上搜解法,找到一个很厉害的公式: https://www.zhihu.com/question/28792904
共有  ((n^6+3*n^4+12*n^3+8*n^2)/24 种。

代码如下:

#include<stdio.h>
#include<iostream>
#define mo 1000000007
using namespace std;
long long get_mod(int a, int b)
{
    long long result = 1;
    while(b--)
    {
        result = result * a ;
    }
    return result;
}
int main()
{
    int i;
    while(~scanf("%d",&i))
    {
        int64_t res;
        res=((get_mod(i,6)+3*get_mod(i,4)+12*get_mod(i,3)+8*get_mod(i,2))/24)%mo;
        printf("%I64d\n",res);
    }
    return 0;
}

————————————

关于对1000000007取模

在结果过大,超过int64的范围的时候就会溢出,所以一般要求对1e9+7取模,为什么一定是1e9+7?网上说有以下两个理由:
(1)1e9+7是个质数
(2)1e9+7的平方存在int64中刚好不会溢出

取模还有如下性质:
(1)(a+b)%c=(a%c+b%c)%c
(2)(a*b)%c=((a%c)*(b%c))%c
(3)(a/b)%c !=((a%c)/(b%c))%c

当我们对一个数取高次幂时经常也会遇到溢出的情况,a的b次幂对c取模的函数:
long long get_mod(int a,int b,int c)
{
    long long res=1;
    while(b--)
    {
        res*=a;
        res%=c;
    }
    return res;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值