zoukankan      html  css  js  c++  java
  • Codeforces 897 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, .

    题意就是回文,而且回文的长度是偶数,将前k个符合条件的加起来然后%p。

    直接将这个回文分成两半,将前一半的反转一下就是后面一半的。

    代码:

     1 //B.Chtholly's request 处理前一半
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 using namespace std;
     8 typedef long long ll;
     9 const int N=1e5+10;
    10 int h;
    11 ll s[N];
    12 int zz(int n){
    13     int a[10];
    14     while(n!=0){
    15         a[h++]=n%10;
    16         n/=10;
    17     }
    18     int ans=0;
    19     for(int i=0;i<h;i++){
    20         ans=ans*10+a[i];
    21     }
    22     return ans;
    23 }
    24 int main(){
    25     int k,p;
    26     ll ans;
    27     while(~scanf("%d%d",&k,&p)){
    28         for(int i=1;i<=k;i++){
    29             h=0;
    30             int x=zz(i);
    31             s[i]=i*pow(10,h)+x;
    32         }
    33         ans=0;
    34         for(int i=1;i<=k;i++){
    35             ans=(ans+s[i])%p;
    36         }
    37         printf("%lld
    ",ans);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    ATM项目分析
    Python常用模块大全
    一文了解@Conditional注解说明和使用
    Spring IOC源码分析之-刷新前的准备工作
    Spring Cloud Zuul API服务网关之请求路由
    ArrayList相关方法介绍及源码分析
    记一次序列化的JSON解析问题
    大型网站架构演化发展历程
    Spring Cloud Ribbon负载均衡
    Spring Cloud Hystrix 服务容错保护
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9695404.html
Copyright © 2011-2022 走看看