HDOJ 4704 Sum 规律 欧拉定理

规律 欧拉定理:

找规律 2^n-1 ,n 很大用欧拉定理

Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1465    Accepted Submission(s): 622

Problem Description

Sample Input

2

Sample Output

2

Hint

1.  For N = 2, S(1) = S(2) = 1.

2.  The input file consists of multiple test cases.

Source

2013 Multi-University Training Contest 10

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long int LL;

const LL mod=1e9+7;
const LL phi=1e9+6;

char str[200000];

LL quickpow(LL x)
{
  if(x==0LL) return 1LL;
  LL e=2,ret=1;
  while(x)
    {
      if(x%2)
        ret=(ret*e)%mod;
      e=(e*e)%mod;
      x/=2LL;
    }
  return ret;
}

int main()
{
  while(scanf("%s",str)!=EOF)
    {
      int len=strlen(str);
      /// N - 1
      if(str[len-1]>'0')
        {
          str[len-1]--;
        }
      else
        {
          int p=len-1;
          while(str[p]=='0')
            {
              str[p]='9';
              p--;
            }
          str[p]--;
        }
      LL ret=0;
      for(int i=0;i<len;i++)
        {
          ret=ret*10LL+str[i]-'0';
          while(ret>=phi)
            ret-=phi;
        }
      cout<<quickpow(ret)<<endl;
    }
  return 0;
}
时间: 2024-10-28 23:02:01

HDOJ 4704 Sum 规律 欧拉定理的相关文章

【HDOJ】4704 Sum

数学题.f(n) = 2^(n-1) mod (1e9+7). 1 #include <cstdio> 2 3 #define MAXN 100005 4 5 char buf[MAXN]; 6 __int64 phi = 1e9+6; 7 __int64 mod = 1e9+7; 8 9 __int64 power2(__int64 n) { 10 __int64 ret = 1, base = 2; 11 12 --n; 13 while (n) { 14 if (n & 1) 1

Lowbit Sum 规律

Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    ans += lowbit(i)lowbit(i)的意思是将i转化成二进制数之后,只保留最低位的1及其后面的0,截断前面的内容,然后再转成10进制数比

HDU 4704 Sum( 费马小定理 )

HDU 4704 Sum( 费马小定理 ) 理解能力果然拙计,,题目看半天没懂什么意思. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; #define MOD 1000000007 char str[100010]; LL fast_mod( LL a, int b) { LL res = 1; while( b )

hdu 4704 Sum (费马小定理+快速幂)

//(2^n-1)%mod //费马小定理:a^n ≡ a^(n%(m-1)) * a^(m-1)≡ a^(n%(m-1)) (mod m) # include <stdio.h> # include <algorithm> # include <string.h> # define mod 1000000007 using namespace std; __int64 pow(__int64 n) { __int64 p=1,q=2; while(n) { if(n%

HDU 4704 Sum (隔板原理 + 费马小定理)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4704 题意: 给定一个数n 将其分解,Si 表示将n拆成i个数的方案数 求sum( si ) 1<=i<=n; 分析: 隔板原理,  n个木棍,n-1个缝, 分成1份则是C(n-1,0); 分成2份则是C(n-1,1); 分成3份则是C(n-1,2); ... 分成n份则是C(n-1,n-1); ans = sum( C(n-1,i) )   (0<=i<=n-1) =2^(n-1)

HDU 4704 Sum (高精度+快速幂+费马小定理+二项式定理)

Sum Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4704 Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases. 题意:给定一

HDU 4704 Sum(隔板原理+组合数求和公式+费马小定理+快速幂)

题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases. 题意是输入一个N,求N被分成1个数的结果+被分成2个数的结果+...+被分成N个数的结果,N很大 1.隔板原理 1~N有

hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                         (全题文末) 知识点: 整数n有种和分解方法. 费马小定理:p是质数,若p不能整除a,则 a^(p-1) ≡1(mod p).可利用费马小定理降素数幂. 当m为素数,(m必须是素数才能用费马小定理) a=2时.(a=2只是题中条件,a可以为其他值) mod m =  *      //  k=

HDOJ 5150 Sum Sum Sum Miller_Rabin

很少有这么裸的题目,测一下Miller_Rabin Sum Sum Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 72    Accepted Submission(s): 52 Problem Description We call a positive number X P-number if there is not a