A. Giga-Kilo-Gigabyte

A. Giga-Kilo-Gigabyte

https://codeforces.com/group/5yyKg9gx7m/contest/281123/problem/A
As you probably already know one byte is 8 bits, 1024 bytes is 1 kilobyte, 1024 kilobytes are 1 megabyte, etc. The most common known prefixes to display units are the following:

1000units=1kilounit

1000kilounits=1megaunit

1000megaunits=1gigaunit

1000gigaunits=1teraunit

1000teraunits=1petaunit

1000petaunits=1exaunit

1000exaunits=1zettaunit

1000zettaunits=1yottaunit
Due to the fact that 210=1024 is the closest number to 1000, we say that 1024 bytes are 1 kilobyte, for this problem we will ignore this rule of thumb and assume that 1000 bytes are 1 kilobyte. In the country of Diegolandia it is widely known that 1 zettabyte is 1021 bytes, however Diego knows that it's possible to prepend different prefixes and to stack them together to represent a higher amount, for example 1 gigabyte can be 1 kilo-kilobyte (1000 kilobytes). In the case of the zettabyte, Diego knows it can be represented as 1 giga-kilo-gigabyte (109∗103∗109=1021), it can also be represented a 1 kilo-giga-gigabyte, or 1 exa-kilobyte, or 1 kilo-exabyte, etc. In this problem we only care about how many different ways Diego can prepend the different prefixes (all the way from kilo to yotta), since this number might be huge print it modulo 109+7.

Input
An integer T the number of test cases (1<=T<=105). Followed by T lines, each with 1 number N (3<=N<106), which means that Diego wants to know in how many ways he can prepend the different known prefixes to display units to represent the number 10N. It is guaranteed that N will be divisible by 3.

Output
For each test case print a single line with a single integer representing the amount of ways Diego can prepend the known prefixes to display units to represent the number 10N, remember to print this number modulo 109+7
Example
inputCopy
5
3
6
9
12
24
outputCopy
1
2
4
8
128

题目描述:

有10^n(n=3,6,9,12,15,18,21,24)一共8个单位,问用这些单位表示更大的10^k,有多少种方式。比如10^910^310^9=10^21是其中一种。

分析:

因为单位变化只对10^3倍数有影响,所以只讨论k%3==0的情况:

把k的几种取值列出来:

比如k=3:可以分成10^3,下面就记为3。

k=3:
+3
---------------
k=6:
+6
3 +3
---------------
k=9:
+9
3 +6
6 +3
3 3 +3
---------------
k=12:
+12
3 +9
6 +6
3 3 +6
9 +3
3 6 +3
6 3 +3
3 3 3 +3

不难看出,k=6就是k=3和k=0的组合后分别加3,6 。k=9就是k=6和k=3和k=0的组合后面分别+3,6,9.....依次下去

因为可加的最大只能是24,所以,只要求前24项的和.

 代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<deque>
#include<cmath>
#include<map>
#define sd(x) scanf("%d",&x)
#define ms(x) memset(x,0,sizeof x)
#define fr(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn=1e6+6;
const int mod=1e9+7;
ll dp[maxn];
int main()
{
    dp[0]=0,dp[1]=1;
    for(int i=2;i<9;i++) dp[i]=dp[i-1]*2%mod;
    for(int i=9;i<maxn/3;i++)
    {
        for(int j=1;j<9;j++)
        {
            dp[i]=(dp[i]+dp[i-j])%mod;
        }
    }
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        sd(n);
        printf("%lld\n",dp[n/3]);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/studyshare777/p/12942114.html