cf C. Prime Number
http://codeforces.com/contest/359/problem/C
先求出分子的公因子,然后根据分子上会除以公因子会长生1,然后记录1的个数就可以。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 200000
#define LL __int64
using namespace std; LL a[maxn];
LL n,x;
LL min1(LL s,LL d)
{
if(s>d)return d;
return s;
} LL pow_mod(LL a,LL p,LL m)//快速幂取模
{
if(p==) return ;
LL ans1=pow_mod(a,p/,m);
ans1=ans1*ans1%m;
if(p%==) ans1=ans1*a%m;
return ans1;
} int main()
{
while(scanf("%I64d%I64d",&n,&x)!=EOF)
{
LL sum=;
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
sum+=a[i];
}
LL ans=sum-a[n];//分子中最小公因子
LL c=a[n];
int t1=;//记录可以产生1的个数
int pos=n;
while(c>=)
{
while(a[pos]==c&&pos>=)
{
pos--;
t1++;
}
c--;
if(t1%x==)
{
ans++;
t1/=x;
}
else
break;
}
ans=min1(ans,sum);
printf("%I64d\n",pow_mod(x,ans,));
}
return ;
}
cf C. Prime Number的更多相关文章
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 每日一九度之 题目1040:Prime Number
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6732 解决:2738 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...
- LintCode-Kth Prime Number.
Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. The eli ...
- 10 001st prime number
这真是一个耗CPU的运算,怪不得现在因式分解和素数查找现在都用于加密运算. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13 ...
- [LeetCode] Prime Number of Set Bits in Binary Representation 二进制表示中的非零位个数为质数
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...
- [Swift]LeetCode762. 二进制表示中质数个计算置位 | Prime Number of Set Bits in Binary Representation
Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...
- 10_ for 练习 _ is Prime Number ?
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量
[抄题]: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a ...
- LeetCode 762 Prime Number of Set Bits in Binary Representation 解题报告
题目要求 Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a ...
随机推荐
- Spring-mvc junit单元测试中 如何回滚?
@RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration(value = "src/main/webapp") @C ...
- javaweb笔记1之入门
1 web应用的目录结构 web的根目录自定义 其中可以包括静态资源(html,image,css,js) |-WEB-INF(注意格式就是这样,大小写等等一模一样) |-class:存放的是字节码文 ...
- 查询死锁和处理死锁(SqlServer)
-------------------查询死锁,极其引起的原因-------------------------------use master go create procedure sp_who_ ...
- 关于数据表命名为mysql保留的时候的操作
今天操作数据表的时候,发现order数据表无法进行操作,必须加上反单引号才能进行操作,查了一下原因: 反引号是用来区别mysql关键字的,比如,如果你有一个表名叫select,你就必须写成`selec ...
- mac 环境下使用virtual box 虚拟机(win7)与主机之间互相ping通
首先选择virtual box设置网络连接方式为网桥 混杂模式设置为全部允许 如下图: 进入虚拟机把虚拟机IP设置和主机在一个网段.如主机是192.168.1.100虚拟机可以设置为192.168.1 ...
- UITableView的刷新
UITableView的刷新1> 数据刷新的总体步骤* 修改模型数据* 刷新表格(刷新界面) 2> 刷新表格(刷新界面)的方法* 全局刷新(每一行都会重新刷新)- (void)reload ...
- jQuery插件开发 格式与解析3之$.extend()用途
前叙:$.extend()——用途:扩展和继承 1.Object extend() 用一个或多个对象扩展另一个对象,并返回已修改的原始对象.这对于简单继承是一个非常有用的实用工具. (1)扩展:(Do ...
- [Polymer] Introduction
install Polymer and explore creating our first custom element: bower install polymer index.html: < ...
- Android 属性动画(二)
当然了属性动画还有一部分的知识点,也能做出很不错的效果,将在本篇博客为您展示~ 1.如何使用xml文件来创建属性动画 大家肯定都清楚,View Animator .Drawable Animator都 ...
- android离线下载的相关知识
离线下载的功能点如下: 1.下载管理(开始.取消下载). 2.网络判断(Wi-Fi,3G). 3.独立进程. 4.定时和手机催醒. 5.自启动. 选择 ...