Link/Cut Tree CodeForces
来源:互联网 发布:飞翔打印软件免费版 编辑:程序博客网 时间:2024/05/16 14:13
拿到这道题一看,题意很简单,要你输出l,r里 k的power次,不存在的话输出-1;一开始简单的看了一下数据范围,感觉没什么问题。 后来发现,数据大一点的话很有可能就会溢出,那么再加个判断就可以解决溢出的问题。
/***If I get TLE , it is good.If I get AC,it's NICE !***/#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <vector>#include <cmath>#include <queue>#include <string>#include <sstream>#include <map>#include <set>using namespace std;typedef long long ll;const int INF=2147483647;const int MAXN=1e5+10;const ll mod=1e9+7;using namespace std;typedef long long ll;int main(void){ ll l, r,k; cin >> l >>r >>k; if(k>r && l==1) { printf("1\n"); return 0; } ll x=1; int flag=0; while(x<=r) { if(x>=l && x<=r) {flag=1;break;} x*=k; if(x%k!=0) break; } if(flag==0) { printf("-1\n"); return 0; } ll ans=1; int cnt=1; while(ans<=r) { if(ans>=l && ans<=r) { if(cnt==1) { printf("%I64d",ans); cnt=2; } else printf(" %I64d",ans); } ll t=ans; ans=ans*k; if(ans % t!=0) break; if(ans%k!=0) break; } puts("");}
阅读全文
0 0
- Link/Cut Tree CodeForces
- Codeforces 614 A Link/Cut Tree
- codeforces 614A Link/Cut Tree
- CodeForces 614A Link/Cut Tree
- codeforces 614A Link/Cut Tree
- codeforces 614 A. Link/Cut Tree
- 【CodeForces】[614A]Link/Cut Tree
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree
- Codeforces Round #339 (Div. 2) A.Link/Cut Tree
- Codeforces Round #339 (Div. 2) A. Link/Cut Tree
- CodeForces 614 A. Link/Cut Tree(水~)
- Codeforces--614A--Link/Cut Tree(数学)(暴力求解)
- CodeForces 614A. Link/Cut Tree【坑精度!!!】
- Codeforces-----614A---Link/Cut Tree---数学水题
- 【link-cut tree】
- Link Cut Tree (paint)
- link-cut-tree
- Link-Cut Tree
- learning之观察者模式
- android studio导入第三方project报红,gradle与gradle插件版本问题
- MySQL触发器语法详解
- Linux_入门之用户和文件
- VS2015 + Qt5.7 环境搭建
- Link/Cut Tree CodeForces
- 手势识别论文解读
- iOS编程学习十四
- 为什么选择Spring Boot作为微服务的入门级微框架
- c语言编写完数的代码
- 【经验】Windows 安装 Redis服务
- Vjudge-140555(E)--CF(371C)
- 华为荣耀微信支付报错
- 第一篇:微信公众平台开发实战Java版之了解微信公众平台基础知识以及资料准备