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;  
    }  
  • 相关阅读:
    ecos启动流程分析
    ecos中断机制分析(2)
    Redboot修改实例
    6/6 项目开工
    6/8 可配置工作流 实现思路
    6/7 第2次碰头
    6/10 主要流程和界面讨论会确定
    6/10 设计方案目录草案
    C# 获取某月的第一天和最后一天
    【Manage It】之掌控项目
  • 原文地址:https://www.cnblogs.com/cancangood/p/3434300.html
Copyright © 2011-2022 走看看