zoukankan      html  css  js  c++  java
  • 20191027-乘方取余

    2018年初赛奥赛题(8分):

    代码: 

    1. #include "stdafx.h"

    2. #include <cstdio> 

    3. int main()

    4. {  int x;

    5.    scanf_s("%d",&x);

    6.   int res=0;

    7. for(int i=0;i<x;++i)

    8. { if (i*i%x==1)

    9. {++res;}

    10. }

    11. cout<<"共有:"<<res<<"个符合条件的数"<<endl;

    12. } 

    输入:15

     

    求输出内容 4

    解题思路:

        分别对0-14进行乘方(i的值从0到14),再取余,如果余数是1,则计数器res增加1,那符合条件的数有1,4,11,14,可以在 ++res;语句后面增加一行 cout<<i<<endl;  就可以看到这4个数 

  • 相关阅读:
    flex-direction
    flex-grow
    Push API
    ServiceWorker.state
    Using Service Workers
    Promise.then
    Promise()
    Using promises
    node-rsa
    async.waterfall
  • 原文地址:https://www.cnblogs.com/whcsrj/p/12929409.html
Copyright © 2011-2022 走看看