Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3980    Accepted Submission(s): 1620

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
 
Recommend
zhuyuanchen520
 
 
一道学长教的数论题。找出规律后发现求的是2^(n-1)。
利用费马小定理欧拉降幂
由于n非常大,可采用字符串读入,读入同时分位取余(((a*100%MOD)+b*10%NOD)+c%MOD)%MOD,最后跑一边快速幂。
注意n-1,MOD-1
适用于Java大数超时的情况。
--------------------------------------------------------------
ps:后续。竟然成为了18年网络赛的原题...
 
 
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define MAX 1000005
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std; typedef long long ll; ll qMod(ll a,ll b){
ll ans=;
while(b>){
if(b&) ans=ans*a%MOD;
b>>=;
a=a*a%MOD;
}
return ans;
}
int main()
{
int n,len,i;
char s[MAX];
while(~scanf(" %s",s)){
ll c=;
len=strlen(s);
for(i=;i<len;i++){
int x=s[i]-'';
c=c*+x;
if(c>) c%=;
}
c=((c-)%+)%;
printf("%lld\n",qMod(,c));
}
return ;
}

HDU - 4704 sum 大数取余+欧拉降幂的更多相关文章

  1. 2019计蒜之道初赛3 D. 阿里巴巴协助征战SARS(困难)(大数取余+欧拉降幂)

    阿里巴巴协助征战SARS(困难) 33.29% 1000ms 262144K   目前,SARS 病毒的研究在世界范围内进行,经科学家研究发现,该病毒及其变种的 DNA 的一条单链中,胞嘧啶.腺嘧啶均 ...

  2. hdu 1226 bfs+余数判重+大数取余

    题目: 超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. 1214 - Large Division -- LightOj(大数取余)

    http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...

  4. POJ2635The Embarrassed Cryptographer(大数取余+素数筛选+好题)

    题目链接 题意:K是由两个素数乘积,如果最小的素数小于L,输出BAD最小的素数,否则输出GOOD 分析 素数打表将 L 大点的素数打出来,一定要比L大,然后就开始枚举,只需K对 素数 取余 看看是否为 ...

  5. java大数取余

    java大数取余: 类方法:BigInteger.divideAndRemainder() 返回一个数组,key = 0为商key = 1为余数 import java.util.*; import ...

  6. HDU 2814 斐波那契循环节 欧拉降幂

    一看就是欧拉降幂,问题是怎么求$fib(a^b)$,C给的那么小显然还是要找循环节.数据范围出的很那啥..unsigned long long注意用防爆的乘法 /** @Date : 2017-09- ...

  7. Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)

    题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...

  8. 题解报告:hdu 4704 Sum(扩展欧拉定理)

    Problem Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input ...

  9. Sum(欧拉降幂+快速幂)

    Input 2 Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cas ...

随机推荐

  1. 为什么需要onRoute函数?

    为什么需要onRoute函数? · Tencent/wepy Wiki https://github.com/Tencent/wepy/wiki/%E4%B8%BA%E4%BB%80%E4%B9%88 ...

  2. (图解)Description Resource Path Location Type Java compiler level does not match the version of

    Description Resource Path Location Type Java compiler level does not match the version of project 编译 ...

  3. 使用CL命令编译cpp文件

    缘起,我的vs 2003无法新建工程,又不喜欢用vs 2013那样的重量级开发工具(就写两行代码,测试测试一些基本的语法规则或算法). 想来vs应该可以像GCC或G++那样直接用命令行编译Cpp文件, ...

  4. Centos 6.3 编译安装Nginx+php+Mysql

    1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables 将 -A INPUT -m state --state NEW -m tcp -p tcp --dpo ...

  5. 常用JS组件整理

    1.漂亮的弹出层----artDialog http://aui.github.io/artDialog/ 2.弹出层 ------layer http://sentsin.com/jquery/la ...

  6. linux应用之apache的源码安装(centos)

    第一部分:前期准备 需要下载的东西 下载 Apache 源码包  下载地址: http://httpd.apache.org/download.cgi                          ...

  7. HDU 1850 Being a Good Boy in Spring Festival(博弈·Nim游戏)

    Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32 ...

  8. IntelliJ IDEA 中详细图解记录如何连接MySQL数据库

  9. tensorflow kmeans 聚类

    iris: # -*- coding: utf-8 -*- # K-means with TensorFlow #---------------------------------- # # This ...

  10. hdu1520树形dp入门

    题目链接 题意:要开派对,邀请了上司就不能邀请他的下属,邀请了下属就不能邀请他的上司,每个人有一个值,求邀请的人的总值最大 第一行给出一个数n,代表有n个人. 下面n行分别给出n个人的的值 再下面n行 ...