牛客网练习赛18 最大乘积

  • Post author:
  • Post category:其他


#include<stdio.h>
#include<math.h>

int main () {
    int t;
    scanf("%d", &t);
    while(t--) {
        int a, count, m;
        scanf("%d", &a);
        if(a == 1) {
            printf("1\n");
            continue;
        }
        count = a / 3;
        m = a % 3;
        if(m == 1) {
            m = 4;
            count = count -1;
        }
        long long ans = 1;
        for(int i = 1; i <= count; i++) {
            ans *= 3;
            ans %= 2000000000000000003;
        }
        if(m != 0) {
            ans *= m;
        }
        printf("%lld\n", ans);
    }

    return 0;
}



版权声明:本文为AC_greener原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。