hdu 3923 Invoker c中颜色染n个格子,旋转和翻转算一种

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并重点介绍了AI音视频处理在游戏中的应用,如语音识别、图像处理、AR特效等。同时,文章还涉及了自动化测试、性能优化等现代开发流程,旨在为游戏开发者提供全面的技术指导。
 
Problem Description
On of Vance's favourite hero is Invoker, Kael. As many people knows Kael can control the elements and combine them to invoke a powerful skill. Vance like Kael very much so he changes the map to make Kael more powerful.

In his new map, Kael can control n kind of elements and he can put m elements equal-spacedly on a magic ring and combine them to invoke a new skill. But if a arrangement can change into another by rotate the magic ring or reverse the ring along the axis, they will invoke the same skill. Now give you n and m how many different skill can Kael invoke? As the number maybe too large, just output the answer mod 1000000007.
 


 

Input
The first line contains a single positive integer T( T <= 500 ), indicates the number of test cases.
For each test case: give you two positive integers n and m. ( 1 <= n, m <= 10000 )
 


 

Output
For each test case: output the case number as shown and then output the answer mod 1000000007 in a line. Look sample for more information.
 


 

Sample Input
2 3 4 1 2
 


 

Sample Output
Case #1: 21 Case #2: 1
Hint
For Case #1: we assume a,b,c are the 3 kinds of elements. Here are the 21 different arrangements to invoke the skills / aaaa / aaab / aaac / aabb / aabc / aacc / abab / / abac / abbb / abbc / abcb / abcc / acac / acbc / / accc / bbbb / bbbc / bbcc / bcbc / bccc / cccc /

 

//

 

#include <cstdio>
const int mod=1000000007;
int fun(int a,int n)
{
    if(n==1) return a%mod;
    if(n==0) return 1;
    long long t=fun(a,n/2);
    t=(t*t)%mod;//important
    if(n&1) return (t*a)%mod;
    else return t%mod;
}
int euler(int n)
{
    int ans = n;
    for (int i = 2; i <= n; i++) if (n % i == 0)
        {
            ans -= ans / i;
            while (n % i == 0) n /= i;
        }
    if (n > 1) ans -= ans / n;
    return ans;
}
//求(a/b)%p,gcd(B,p)=1
__int64 exgcd(__int64 a,__int64 b,__int64& x,__int64& y)
{
    if(b==0) return x=1,y=0,a;
    __int64 r=exgcd(b,a%b,x,y);
    __int64 t=x;
    x=y;
    y=t-(a/b)*y;
    return r;
}
__int64 calc(__int64 a,__int64 b,__int64 mod)
{
    __int64 x,y;
    __int64 r=exgcd(b,mod,x,y);
    x*=a;
    x=(x%mod+mod)%mod;
    return x;
}
int main()
{
    int n, c;
    int cas = 1, T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d%d", &c, &n);
        if (n == 0)
        {
            printf("0\n");
            continue;
        }
        __int64 ans = 0;
        for (int i = 1; i <= n; i++)
        if (n % i == 0)
            {
                ans += (long long)fun(c, i) * euler(n / i);
                ans %= mod;
            }//枚举个数
        if (n & 1)
        {
            ans += (long long)n * fun(c, n / 2 + 1);
            ans %= mod;
        }
        else
        {
            ans += (long long)n / 2 * (fun(c, n / 2) + fun(c, n / 2 + 1));
            ans %= mod;
        }
//        ans /= (2 * n);
//        ans %= mod;
        ans=calc(ans,(long long)2*n,(long long)mod);
        printf("Case #%d: %I64d\n",cas++, ans);
    }
    return 0;
}


 

### 问题描述 在hdu 2091空心三角形问题中,每行输入包含一个字符一个整数`n`(0 < `n` < 41),不同字符代表不同花纹,整数`n`表示等腰三角形的高,其底边长为2`n` - 1。当遇到`@`字符时,停止输出样板三角形。每个样板三角形之间需空一行,且三角形中间为空,行末无多余空格[^1][^2][^3][^5]。 ### 代码实现 以下是几种使用C语言解决该问题的代码示例: #### 代码示例1 ```c #include<stdio.h> int main() { char c; int n; int i,j; int flag=0; while(scanf("%c",&c)) { if(c=='@') break; scanf("%d",&n); if(flag) printf("\n"); flag=1; if(n==1) { printf("%c\n",c); } else { for(i=0;i<n-1;i++) printf(" "); printf("%c\n",c); for(i=1;i<n-1;i++) { for(j=1;j<n-i;j++) printf(" "); printf("%c",c); for(j=1;j<=2*i-1;j++) printf(" "); printf("%c\n",c); } for(i=0;i<2*n-1;i++) printf("%c",c); printf("\n"); } getchar(); } return 0; } ``` #### 代码示例2 ```c #include<stdio.h> int main() { int n,i,j,m,t=1; char c; while(scanf("%c",&c)!=EOF) { if(c=='@') break; else { scanf("%d",&n); getchar(); if(t==1) t=0; else printf("\n"); m=2*n-1; for(i=1;i<=n;i++) { if(i==n) { while(m--) printf("%c",c); printf("\n"); } else { for(j=1;j<=n;j++) if(j==n-i+1) printf("%c",c); else printf(" "); for(j=1;j<=i-1;j++) if(j==i-1) printf("%c",c); else printf(" "); printf("\n"); } } } } return 0; } ``` #### 代码示例3 ```c #include<stdio.h> int main(void) { char ch; int n; int flag = 0; while (1) { scanf("%c", &ch); if (ch == '@') return 0; scanf("%d", &n); getchar(); if (flag) putchar('\n'); if (n == 1) { printf("%c\n", ch); continue; } for (int i = 0; i < n-1; i++) { putchar(' '); } putchar(ch); putchar('\n'); for (int i = 1; i < n-1; i++) { for (int j = n-i; j > 0; j--) { if (j != 1) putchar(' '); else putchar(ch); } for (int k = 2 * i - 1; k > 0; k--) { putchar(' '); } putchar(ch); putchar('\n'); } for (int i = 0; i < 2*n-1; i++) putchar(ch); putchar('\n'); flag = 1; } return 0; } ``` ### 思路分析 1. **输入处理**:使用`while`循环读取输入,当遇到`@`字符时,终止循环。每次读取一个字符一个整数`n`,并处理输入缓冲区的换行符[^1][^2][^5]。 2. **输出格式控制**:使用一个标志变量(如`flag`或`t`)来控制每个样板三角形之间的空行输出。第一个三角形前不输出空行,后续三角形前输出空行[^1][^2][^5]。 3. **特殊情况处理**:当`n`等于1时,直接输出该字符并换行[^1][^5]。 4. **三角形输出**: - **第一行**:输出`n - 1`个空格一个字符,然后换行。 - **中间行**:每行先输出`n - i - 1`个空格,再输出一个字符,接着输出`2 * i - 1`个空格,最后输出一个字符并换行(`i`表示当前行数,从1开始)。 - **最后一行**:输出`2 * n - 1`个字符并换行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值