zoukankan      html  css  js  c++  java
  • HDU-2817 A sequence of numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=2817

    学习 ://(a × b) mod c=( (a mod c) × b) mod c.

            (a+b)mod c=(a mod c+b mod  c)mod c;

     在题目中我们总会遇到   a^b mod n 所以我们必须用 快速幂取模算法,下面就是快速 快速幂取模算法,这些强制类型转换应该要多学习学习。

    题意是等比数列或者等差数列,求第k个数。求余200907。

                       A sequence of numbers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2208    Accepted Submission(s): 697

    Problem Description
    Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only the first three numbers of each sequence are recognizable. Xinlv wants to know some numbers in these sequences, and he needs your help.
     
    Input
    The first line contains an integer N, indicting that there are N sequences. Each of the following N lines contain four integers. The first three indicating the first three numbers of the sequence, and the last one is K, indicating that we want to know the K-th numbers of the sequence.
    You can assume 0 < K <= 10^9, and the other three numbers are in the range [0, 2^63). All the numbers of the sequences are integers. And the sequences are non-decreasing.
     
    Output
    Output one line for each test case, that is, the K-th number module (%) 200907.
     
    Sample Input
    2
    1 2 3 5
    1 2 4 5
     
    Sample Output
    5
    16
    //(a × b) mod c=( (a mod c) × b) mod c.
    #include<stdio.h>  
    #include<string.h>  
    #define MOD 200907  
      __int64 quickmod(__int64 a,__int64 b,__int64 n)//快速幂取模算法 a^b mod n 
    {  
        __int64 ret=1;  
        for (; b; b>>=1,a=(__int64)(((__int64)a)*a%n))  
            if (b&1)  
                ret=(__int64)(((__int64)ret)*a%n);  
        return ret;  
    }  
      
      
    int main()  //注意这些强制类型转换,还是要换变量。
    {  
        double a,b,c;  
        int t;  
        int k;  
        scanf("%d",&t);  
        while(t--)  
        {  
            scanf("%lf%lf%lf%d",&a,&b,&c,&k);  
            if(a+c==2*b)  
            {  
                __int64 a1=(__int64 )a;  
                __int64 d=(__int64 )(b-a);  
                int ans=(a1%MOD+((k-1)%MOD)*(d%MOD))%MOD;  
                printf("%d
    ",ans);  
            }  
            else  
            {  
                __int64 a1=(__int64)a;  
                __int64 t1=(__int64)(a1%MOD);  
                double q1=(b/a);  
                __int64 q2=(__int64)q1;  
                __int64 q=(__int64)q2;  
                __int64 tmp=quickmod(q,k-1,MOD);  
                int ans=(t1*tmp)%MOD;  
                 printf("%d
    ",ans);  
            }  
        }  
        return 0;  
    }  
  • 相关阅读:
    如何上架一个iOS APP(2020年最新版教程)
    可以在Windows申请iOS证书上架iOS APP---Appuploader
    上传了ipa但iTunes Connect没有构建版本问题
    iOS证书类型介绍及申请教程
    APP专用密码app-specific password怎么设置
    Windows电脑申请iOS证书教程及工具分享
    【2020】申请iOS个人开发者账号流程
    【分享】使用免费的苹果开发者账号申请iOS证书打包测试教程
    iOS证书及描述文件制作流程详解
    linux /bin/bash^M: bad interpreter的解决办法
  • 原文地址:https://www.cnblogs.com/cancangood/p/3434300.html
Copyright © 2011-2022 走看看