题目很简单,就是求表达式(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. ABP-添加表

    1.在My_ABP.Core根目录下先创建一个文件夹,在该文件夹里创建一个公共的类,在里面定义所需要用到的属性 public class Person:Entity      {         pu ...

  2. 手机端 https://doc.vux.li/zh-CN/components/badge.html

    https://doc.vux.li/zh-CN/components/badge.html 手机端前端框架

  3. node—基础命令

    1.安装node,在任意文件夹下按shift键选中“在此处打开PowerShell窗口”或者直接在开始菜单输入cmd启动 2.常用命令: c: 如果我们想访问c盘,那么我们需要在命令行中输入c:就行了 ...

  4. zabbix 配合钉钉群机器人(webhook) 报警

    首先建钉钉群,添加一个自定义机器人拿到webhook zabbix添加一个报警媒介 搞一个shell脚本来启动Python脚本(直接用zabbix调Python脚本不行,不知道什么原因) vim di ...

  5. HTML5服务器消息推送(java版)

    前端代码(html5.html): <html> <meta http-equiv="Content-Type" content="text/html; ...

  6. git 查看某个文件的修改记录

    有几种方式, (1)如果是在linux环境下,比如centos,ubuntu之类的,建议安装tig命令 炒鸡好用,tig后面可以跟文件或者文件夹,比如: (1.1)tig  dir_name (1.2 ...

  7. 部分还款-还款试算接口与还款接口-python

    一.还款试算.还款接口, 1.只传入参数loan_Code 2.还款接口参数化以下: "loanCode": loanCode1,"orderId": orde ...

  8. 24-Python3 OS

    24-Python3 OS ''' OS文件/目录方法 ''' ##os.access():检验权限模式 fo1 = open('/Users/ligaijiang/PycharmProjects/f ...

  9. cocos2d-x JS 纯代码加载播放plist与png动画

    var cache = cc.spriteFrameCache; cache.addSpriteFrames(plist, png); var frames = []; for (var i = 1; ...

  10. java-Unicode与中文的转换

    package utils; import org.apache.commons.lang3.StringUtils; public class UnicodeUtils { public stati ...