Read the program below carefully then answer the question. 
#pragma comment(linker, "/STACK:1024000000,1024000000") 
#include <cstdio> 
#include<iostream> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
#include<vector>

const int MAX=100000*2; 
const int INF=1e9;

int main() 

  int n,m,ans,i; 
  while(scanf("%d%d",&n,&m)!=EOF) 
  { 
    ans=0; 
    for(i=1;i<=n;i++) 
    { 
      if(i&1)ans=(ans*2+1)%m; 
      else ans=ans*2%m; 
    } 
    printf("%d\n",ans); 
  } 
  return 0; 
}

InputMulti test cases,each line will contain two integers n and m. Process to end of file. 
TechnicalSpecification 
1<=n, m <= 1000000000OutputFor each case,output an integer,represents the output of above program.Sample Input

1 10
3 100

Sample Output

1
5 等比数列二分求和:

(1)时,

(2)时,那么有

(3)时,那么有

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 18
#define N 33
#define MOD 10000007
#define INF 1000000009
const double eps = 1e-;
const double PI = acos(-1.0);
LL n, m, ans;
/*
等比数列二分求和
*/
LL fpow(LL a, LL b)
{
LL ret = , tmp = a;
while (b != )
{
if (b & )
ret = ret*tmp%m;
tmp = tmp*tmp%m;
b /= ;
}
return ret%m;
}
LL sum(LL a, LL k)
{
LL t, cur;
if (k == )
return a;
else if (k % == )
{
t = sum(a, k / ),cur = fpow(a, k / + );
t = (t + t * cur%m) % m;
t = (t + cur) % m;
}
else
{
t = sum(a, k / ), cur = fpow(a, k / );
t = (t + t * cur % m) % m;
}
return t;
}
LL solve(LL num)
{
if (num == )
return ;
else
return ( + sum(, num)) % m;
}
int main()
{
while (cin >> n >> m)
{
if (n & )
cout << solve(n/)%m << endl;
else
cout << solve((n - )/)*%m << endl;
}
}
												

最新文章

  1. Redux状态管理方法与实例
  2. [bigdata] spark集群安装及测试
  3. iOS:使用模板引擎渲染HTML界面
  4. CDS
  5. MVC使用ASP.NET Identity 2.0实现用户身份安全相关功能,比如通过短信或邮件发送安全码,账户锁定等
  6. markdown安装和使用
  7. CSS/JS图片鼠标悬浮一道光闪过
  8. 关于iPhone多点触控
  9. Android Touch事件传递机制解析 (推荐)
  10. nodejs快速入门
  11. MySQL基础之第18章 性能优化
  12. python中xrange和range的区别
  13. DAO 基础学习笔记
  14. LoaderManager使用具体解释(二)---了解LoaderManager
  15. THE R QGRAPH PACKAGE: USING R TO VISUALIZE COMPLEX RELATIONSHIPS AMONG VARIABLES IN A LARGE DATASET, PART ONE
  16. Java语言的9个主要特性
  17. 【Ubuntu 16】安装net-snmp
  18. C#开发WEBService服务 C++开发客户端调用WEBService服务
  19. php中数组直接用加号相加array+array
  20. AI-视图组件-五个接口的最终简化版

热门文章

  1. 理解JavaScript中的闭包
  2. 安卓UI自适应性
  3. 350 Intersection of Two Arrays II 两个数组的交集 II
  4. jsp里post和get的乱码解决问题
  5. Java系列学习(十一)-内部类
  6. [ CTSC 2007 / BZOJ 2151 ] Backup / 种树
  7. activiti 表——介绍
  8. Android进入一个新页面,EditText失去焦点并禁止弹出键盘
  9. SSH整合框架+mysql简单的实现
  10. C# ADO.NET动态数据的增删改查(第五天)