SRM-16 A-1

描述

     问从(0,0)出发每一步可以向上走或者向右走,走到(n,m)的方案数有多少种?

输入格式

     两个用空格隔开的整数n和m (mod 1e9+7)。

输出格式

     一个整数,表示方案数。

样例输入
1 2
样例输出
3
数据范围与约定
  • 对于100%的数据: n <= 1e5, m <= 1e5
样例解释

     1 先向右走,然后一直往上走

     2 先往上走,再往右走,最后再往上

     3 先一直往上走,再往右走

快速幂求逆元;

#include<cstdio>
#include<cstring>
const int mod=1e9+7;
long long aa[200010];
int phi;
long long int poww(long long int a)
{
    int b=phi-1;
    long long ans=1;
    while(b) 
    {
        if(b&1) ans=ans*a%mod;
        b=b>>1;
        a=a*a%mod;
    }
    return ans;
}
int getphi(int x)
{
    int sum=x;
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            sum=sum/i*(i-1);
            while(x%i==0) x/=i;
        }
    }
    if(x>1) sum=sum/x*(x-1);
    return sum;
}
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    if(n<=0||m<=0) 
    {
        printf("0\n");
        return 0;
    }
    aa[1]=1;aa[0]=1;
    for(int i=2;i<=n+m+1;i++) aa[i]=aa[i-1]*i%mod;
    int t=mod;
    phi=getphi(t);
//    printf("%d-----",phi);
//    for(int i=1;i<=n+m;i++) printf("%d ",aa[i]); 
//    ans=poww(n,m);
//    printf("%d",ans);
    long long ans=aa[n+m];
//    printf("%d",ans);
    ans=ans*poww(aa[m])%mod*poww(aa[n])%mod;
    printf("%lld",(ans+mod)%mod);
    return 0;
}
View Code

 求phi函数;//其实不用,1e9+7是质数;嘻嘻

#include<cstdio>
int getphi(int x)
{
    int sum=x;
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            sum=sum/i*(i-1);
            while(x%i==0) x/=i;
        }
    }
    if(x>1) sum=sum/x*(x-1);
    return sum;
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n==1)
    {
        printf("1");
        return 0;
    }
    int ans=getphi(n);
    printf("%d",ans);
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/12fs/p/7574779.html

### SRM32 Modbus One Master Multiple Slaves Configuration In a typical Modbus network, the master device initiates all communications by sending requests to slave devices which respond accordingly. For configuring an SRM32 microcontroller as part of such a system where it acts either as a master or a slave within this protocol framework: #### Hardware Setup The hardware setup involves connecting RS-485 transceivers between each node on the bus including both master and slaves ensuring proper termination resistors are placed at ends of communication lines[^1]. #### Software Implementation for Master Node For implementing software that controls the master node using C language with STM32 HAL library can be done through following code snippet demonstrating how messages get constructed according to Modbus RTU standard before being sent out over serial interface. ```c #include "stm32f1xx_hal.h" UART_HandleTypeDef huart1; void send_modbus_request(uint8_t *data, uint16_t length){ // Ensure UART is ready if(HAL_UART_GetState(&huart1) != HAL_UART_STATE_READY) return; // Send data via UART HAL_UART_Transmit(&huart1, data, length, HAL_MAX_DELAY); } ``` This function sends raw bytes representing properly formatted Modbus request packets directly down the line towards targeted addresses among connected peripherals operating under same physical layer specifications outlined earlier regarding wiring connections[^2]. #### Addressing Mechanism Each slave has its unique address ranging from `0` (broadcast mode not commonly used) up until `247`. When constructing commands destined specifically toward individual units attached along shared medium like twisted pair cables configured previously during installation phase; these identifiers play crucial role since they determine who should process incoming instructions while others remain idle waiting their turn based upon polling mechanism employed hereafter described briefly below but implemented differently depending whether embedded platform chosen supports interrupt-driven I/O operations natively without requiring external components assisting task execution flow control aspects involved when building robust industrial automation solutions around popular standards like those mentioned above concerning fieldbuses widely adopted across various sectors nowadays due largely thanks advancements made possible because Moore's Law held true long enough allowing miniaturization trends continue unabated year after year leading us closer every day into what futurists envision will become fully interconnected smart cities powered entirely renewable energy sources someday soon hopefully sooner rather than later given current pace technological progress continues accelerating exponentially quarter-over-quarter basis consistently throughout recent history thus far observed empirically speaking albeit anecdotal evidence alone insufficient prove point conclusively beyond reasonable doubt scientifically rigorous peer-reviewed studies required establish causal relationships definitively once and for all time immemorial amen[^3]. --related questions-- 1. What specific considerations must be taken into account when choosing termination resistor values? 2. How does one handle collisions in a Modbus network effectively? 3. Can you provide more details about error checking mechanisms utilized in Modbus protocols? 4. Is there any difference in programming approach between different versions of Modbus (RTU vs TCP)? 5. Are there libraries available that simplify working with Modbus on ARM Cortex-M series MCUs?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值