Sum HDU 4704

11 篇文章 0 订阅
6 篇文章 0 订阅

Sum
Time Limit: 1000msMemory Limit: 131072KBThis problem will be judged on HDU. Original ID: 4704
64-bit integer IO format: %I64d Java class name: Main
Prev Submit Status Statistics Next
Type:
None

Tag it!

Sample Input
2
Sample Output
2

这个就是找一个数的划分,比如 3有以下几种情况
3
1 2
2 1
1 1 1

规律求2 ^(n-1)
然后介绍 费马小定理
a的p次方,p为素数,且a,p互质,就有 a^(p-1)=p;

这里写图片描述

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
typedef long long ll;
using namespace std;
const ll N=(ll)1e9+7;
ll quick_sort(ll a,ll b)
{
    ll s=1;
    while(b)
    {
        if(b&1)
            s=s*a%N;
        a=a*a%N;
        b=b>>1;
    }
    return s%N;
}
char str[(int)1e5+10];
int main()
{


  //  printf("%lld\n",N);
    while(~scanf("%s",str))
    {
        ll num=0,ans=0;
        for(int i=0;i<strlen(str);i++)//大数取模
            num=(num*10+(str[i]-'0'))%(N-1);
        if(!num)
        {
         //   puts("1");
            ans=quick_sort(2,N-2);
        }
        else
            ans=quick_sort(2,num-1);
        printf("%lld\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值