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 ...
随机推荐
- oracle11g rac asm 实例内存修改
ASM实例内存修改 memory_max_target(它为静态参数,修改完成后需要重启实例) memory_target(它为动态参数,不需要重启实例) SQL> select name,is ...
- 俄罗斯方块:Python实现
网上搜到一个Pygame写的俄罗斯方块(tetris),大部分看懂的前提下增加了注释,Fedora19下运行OK的 主程序: #coding:utf8 #! /usr/bin/env python # ...
- BZOJ2079: [Poi2010]Guilds
2079: [Poi2010]Guilds Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 237 Solved: 181[Submit][Statu ...
- 【转】你应该知道的 10 个 VirtualBox 技巧与高级特性
原文网址:http://www.oschina.net/translate/10-virtualbox-tricks-and-advanced-features-you-should-know-abo ...
- HDOJ(HDU) 1563 Find your present!(异或)
Problem Description In the new year party, everybody will get a "special present".Now it's ...
- 【7】JAVA---地址App小软件(AddrBusiness.class)(逻辑层)
这个...没多少好解释的... 表现层的增删改查的具体实现类. package cn.hncu.addr.business; import javax.swing.JOptionPane; impor ...
- socket中select的使用源码
下面的代码来自IBM学习网站,是学习socket通信和select使用的一个很好的源码. server.c 服务器端 #include <stdio.h> #include <st ...
- UVa400.Unix ls
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- activity theme parent 属性浅析
在AndroidManifest.xml文件中,可以对每一个Activity设置android:themetheme的设置 可以设置为系统自带的格式,也可以自定义格式. A: 系统自带格式 1.and ...
- [深入React] 5.MVC
react 是一种典型的MVC框架. 在jquery中,我们都是针对dom编程,由dom事件触发dom改变,MVC三层代码混在一起. 比如点击变颜色 $('#btn').click(function( ...