zoukankan      html  css  js  c++  java
  • 449B

    B. Chtholly's request
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output
    — Thanks a lot for today.

    — I experienced so many great things.

    — You gave me memories like dreams... But I have to leave now...

    — One last request, can you...

    — Help me solve a Codeforces problem?

    — ......

    — What?

    Chtholly has been thinking about a problem for days:

    If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

    Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

    Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

    Input

    The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

    Output

    Output single integer — answer to the problem.

    Examples
    Input
    2 100
    Output
    33
    Input
    5 30
    Output
    15
    Note

    In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

    In the second example, .

                          输入n和m,得到前n个长度是偶数的回文数的和 sum,输出sum模上m的值,

      本来用了暴力去解,    但是爆掉了,本来我是从1开始检测,一直检测到第n个符合条件的数结束,

    但是测试数据里有这样一组数

    42147 412393322
    
    #include<stdio.h>
    #include<string.h>
    int main()
    {
     int m,n,i,t,j,h,len,k,d[100000],a,b;
     long long sum;
     char p[11];
     h=1;
     for(i=11;i<=100000;i++)
      {
       k=0;
       d[1]=0;
       sprintf(p,"%d",i);
       len=strlen(p);
       if(len%2==0)
       {
      
        for(j=0;j<(len+1)/2;j++)
           if(p[j]!=p[len-j-1])
           {k=1;break;}
           if(k==0)
           {
      
            d[h+1]=d[h]+i;
            h++;  
           }  
        }d[i]=d[h]; 
        
      }
     while(scanf("%d%d",&n,&m)!=EOF)
     {
      printf("%d\n",d[n+1]%m);
        }
    }

    AC的代码:

    #include<stdio.h>
    int main()
    {
     int m,a,b,i,j;
     long long n,t,t1,sum;
     while(scanf("%lld%d",&n,&m)!=EOF)
     {
      sum=0;
      for(i=1;i<=n;i++)
      {
       t=t1=i;
       while(t!=0)
       {
       t1=t1*10+t%10;
       t/=10;
       }
       sum=(sum+t1)%m;
      }
      
      printf("%lld\n",sum);
     }
    }
  • 相关阅读:
    chrome调试Android webview页面
    Ractive 的 一些认识
    backbone的一些认识
    关于Maven打包(Jar)时文件过滤的正确做法
    网页中实现微信登录(OAuth)的不完整记录
    将项目发布到Maven中央仓库时关于GPG的一些操作日志
    记录一下自己在 eclipse 中使用的 javadoc 模板
    记录一下MySQL的表分区常用操作
    在H5 App中实现自定义Token的注意事项
    再来复习一下Javascript中关于数组和对象的常用方法
  • 原文地址:https://www.cnblogs.com/wenbo4399/p/7991902.html
Copyright © 2011-2022 走看看