zoukankan      html  css  js  c++  java
  • NOIp 2014解方程

    乍看一眼以为是高精,随便写了个usigned long long交上去拿了50分,翻了翻题解才知道用了我没用过的算法——秦九韶算法,算是道模板了吧,不过这道题中的对10^10000的数的处理值得记住,并不是告诉了模一个质数才是模质数的题,凡是位数特别多且不要求求具体答案的大概都可能用到模质数吧

    代码

     1 #include<iostream>
     2 #include<cstdio>
     3 
     4 using namespace std;
     5 
     6 typedef long long ll;
     7 
     8 const int mod = 1e9+7;
     9 
    10 ll read(){
    11     ll ans = 0;char ch = getchar(),last = ch;
    12     while(ch < '0'||ch > '9')last = ch,ch = getchar();
    13     while('0' <= ch&&ch <= '9')ans = (ans*10+ch-'0')%mod,ch = getchar();
    14     if(last == '-')return -ans;return ans;
    15 }
    16 
    17 int a[110],sta[110];
    18 int n,m,top = 0;
    19 
    20 bool check(int x){
    21     ll tot = 0;
    22     for(int i = n;i >= 0;i--)tot = (tot*x + a[i])%mod;
    23     return !tot;
    24 }
    25 
    26 int main(){
    27     n = read(),m = read();
    28     for(int i = 0;i <= n;i++)a[i] = read();
    29     for(int i = 1;i <= m;i++)if(check(i))sta[++top] = i;
    30     printf("%d
    ",top);
    31     for(int i = 1;i <= top;i++)printf("%d
    ",sta[i]);    
    32 return 0;
    33 }
  • 相关阅读:
    虚函数
    class与struct的区别
    HTTP是什么连接
    长连接与短连接
    多线程的主要优点
    overload、override、overwrite的介绍
    常用的Linux命令
    IO模型——IO多路复用机制
    栈区与堆区的区别
    软链接和硬链接到底有啥区别
  • 原文地址:https://www.cnblogs.com/Wangsheng5/p/11530956.html
Copyright © 2011-2022 走看看