codeforces584B Kolya and Tanya

题目链接http://codeforces.com/problemset/problem/584/B

解题思路:当n=1时,_______    _______   ______  三个数每位上可以填1,2,3三个数,所以,所有可能的结果就是3*3*3   不满足条件的有2 2 2这一种情况,还有1 2 3这三个数字,总共有6种情况,所以答案是27-1-6=20;当n=2时,所有可能的结果是3*3*3*3*3*3-?=680 ,可以推测出减去49即7*7

所以找到的规律就是:

当n=1时,   27-7

当n=2时     27*27-7*7

注意点:因为最后要模上一个数,中间去模的过程中要注意

具体代码

#include<bits/stdc++.h>

using namespace std;

#define LL __int64
const LL inf=1000000007;

int main()
{
    int n;
    scanf("%d",&n);
    LL ans=1;
    LL t=1;
    for(int i=1;i<=n;i++)
    {
        ans*=27;
        t*=7;
        ans=ans%inf;
        t=t%inf;
    }
    ans=((ans+inf)-t)%inf;
    printf("%I64d
",ans);
    return 0;
}

 

anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
原文地址:https://www.cnblogs.com/gaoss/p/4862742.html