题目很简单,就是求表达式(P/D)的结果是不是整数。其中P是一个整系数的多项式,D是一个正整数。

把1-k(最高次)+1都试一次就好了。结论可以总结归纳得到。(k取 0, 1, 2 .... 的情况推一次,可以推出结论)。

// Asimple
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#define INF 0x3f3f3f3f
#define mod 1000007
#define debug(a) cout<<#a<<" = "<<a<<endl
#define test() cout<<"============"<<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = +;
ll n, m, T, len, cnt, num, ans, Max, k;
string str;
pair<ll, ll> p[maxn]; ll qpow(ll a, ll b, ll md) {
ll ans = ;
while( b ) {
if( b& ) ans = (ans*a)%md;
a = (a*a)%md;
b >>= ;
}
return ans;
} void solve(int k) {
cnt = ;
for(int i=; str[i]!=')'; ) {
ll first = ;
ll second = ;
bool fg = false;
while( str[i]!='n' && str[i]!=')' ) {
char ch = str[i];
//debug(ch);
if( ch==
'+') { }
else if( ch == '-' ) { fg = true; }
else first = first* + (ch-'');
i ++;
}
if( first == ) first = ;
if( fg ) first *= -;
//debug(first);
i ++;
//printf("i==%d ch==%c\n", i, str[i]); if( str[i]=='/' ) {
second = ;
p[len++] = make_pair(first, second);
break;
} else if( str[i]!='^' ) { second = ; }
else if( str[i]=='^' ) {
i ++;
while( isdigit(str[i]) ) {
second = second*+(str[i]-'');
i ++;
}
}
//debug(second);
p[len++] = make_pair(first, second);
cnt = max(cnt, second);
//debug(cnt);
//debug(len);
} m = ;
for(int i=; i<k; i++) {
if( str[i]=='/' ) {
i ++;
while( isdigit(str[i]) && i<k ) {
m = m* + (str[i]-'' );
i ++;
}
}
}
} void input(){
int cas = ;
while( cin >> str ) {
if( str[] == '.' ) break;
len = ;
k = str.length();
solve(k);
bool f = true;
for(int i=; i<=cnt+; i++) {
ll sum = ;
for(int j=; j<len; j++) {
//printf("first==%d second==%d\n", p[j].first, p[j].second);
sum += (p[j].first*qpow(i, p[j].second, m))%m;
sum %= m;
}
if( sum ) {
f = false;
break;
}
}
cout << "Case " << cas++ << ": ";
if( f ) cout << "Always an integer" << endl;
else cout << "Not always an integer" << endl;
}
} int main() {
input();
return ;
}

Always an integer UVALive - 4119的更多相关文章

  1. UVALive 4119 Always an integer (差分数列,模拟)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Always an integer Time Limit:3000MS     M ...

  2. uvalive 4119 Always an Interger

    差分数列+字符串处理 题意:是让你判断一个整系数多项式的值是否一直都能被一个所给的正整数所整除. 通过对差分数列的不断求导,我们可以发现,对于任意多项式P,我们只需要判断n从1到k+1是否满足就行了, ...

  3. LA 4119 - Always an integer

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  4. LA 4119 (差分数列 多项式) Always an integer

    题意: 给出一个形如(P)/D的多项式,其中P是n的整系数多项式,D为整数. 问是否对于所有的正整数n,该多项式的值都是整数. 分析: 可以用数学归纳法证明,若P(n)是k次多项式,则P(n+1) - ...

  5. LA 4119 Always an integer (数论+模拟)

    ACM-ICPC Live Archive 一道模拟题,题意是问一个给出的多项式代入正整数得到的值是否总是整数. 这题是一道数论题,其实对于这个式子,我们只要计算1~最高次项是否都满足即可. 做的时候 ...

  6. UVALive 4031 Integer Transmission(贪心 + DP)

    分析:求出最大值和最小值比较简单,使用贪心法,求最小值的时候我们让所有的0尽可能的向后延迟就可以了,求最大值则相反. 关键在于求出可以组合出的数字个数. 这就是组合数学版的dp了,我们让dp[i][j ...

  7. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  8. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  9. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

随机推荐

  1. 利用 PorterDuff 动态改变资源色值,缩减安装包大小

    利用 PorterDuff 改变资源原有色值,从而实现只需要一个资源文件,就可以表示几种不同的状态,如在线或者离线等等 public Drawable colorDrawable(Resources ...

  2. EditText的一些使用技巧

    1.让EditText不自动获取焦点 将EditText的某个父级控件设置成 android:focusable="true" android:focusableInTouchMo ...

  3. [Java in NetBeans] Lesson 10. For Loops

    这个课程的参考视频和图片来自youtube. 主要学到的知识点有:(the same use in C/C++) 1. x++, x += 1; similar x--, x -= 1; x *= 2 ...

  4. jQuery发布1.9正式版,最后支持IE 6/7/8

    jQuery 于 2013/1/15 正式发布了 1.9 版本,这个版本最值得关注的,不是又增加了什么新功能,而是它去掉了哪些东西!jQuery 1.9 删除和改动了不少过时的 API,升级后可能会导 ...

  5. iOS UI进阶-6.0 手势

    给每个页面添加手势,只需要统一设置不是根控制器的页面,都增加手势.需要自定义导航控制器 1.继承代理 @interface BSNavigationController ()<UIGesture ...

  6. 27.给input边框和背景颜色设置全透明

    给input边框和背景颜色设置全透明,但是里面的字不会消失 1.让背景颜色变透明(二选一) background-color:rgba(0,0,0,0); background:rgba(0,0,0, ...

  7. HTML-CSS线性渐变

    实现背景的渐变可以通过为背景添加颜色渐变的图片,也可以使用浏览器的功能来为背景添加渐变的颜色 在IE6或IE7浏览器下可以使用一下示例的CSS语句,设置filter属性来实现颜色 filter:pro ...

  8. c#如何判断字符串是否含中文

    如代码: static bool ContainChinese(string input) { string pattern = "[\u4e00-\u9fbb]"; return ...

  9. report源码分析——宏的执行

    uvm_info,uvm_error其实是对uvm_report_info,uvm_report_error的封装. 其中warning,error,fatal,macros默认都是定义为UVM_NO ...

  10. 向量体系结构(2)----SIMD指令集扩展和GPU

    进行SIMD多媒体扩展的设计,源于一个很容易观察到的事实: 许多多媒体应用程序操作的数据类型比对32位处理器进行针对性优化的数据类型更窄一些. 图像三基色,都是8位.音频采样也都是8位和16位来表示. ...