Results 1 to 8 of 8
Thread: C++
Hybrid View
-
5th November 2014 01:39 #1Registered User
Join Date: Jul:2014
Location: Dobrich
Posts: 10
C++
1 n , , 1 endless loop . , .
#include<iostream>
using namespace std;
Code:int main() { int n; cout << "Enter N:"; cin >> n; int automorphicNum = 1; int squareAutoNum = automorphicNum*automorphicNum; while (n != 0) { int y = automorphicNum; int x = squareAutoNum; bool isAutomorphic = true; while (y != 0) { int r = y % 10; int q = x % 10; y /= 10; x /= 10; if (r != q) { isAutomorphic = false; } if (isAutomorphic && y == 0) { n--; cout << automorphicNum<<","; automorphicNum++; } else if (!isAutomorphic && y == 0) { automorphicNum++; } } } return 0; }
-
5th November 2014 07:51 #2
, ... , , squareAutoNum automorphicNum*automorphicNum , . 1. "automorphicNum++; " "if-else", .
, .
.
-
5th November 2014 08:37 #3
while
/ n automorphicNum , for- .Code:for (int automorphicNum = 1; automorphicNum <= n; automorphicNum++)
while.Code:if (isAutomorphic && y == 0) { n--; cout << automorphicNum<<","; automorphicNum++; } else if (!isAutomorphic && y == 0) { automorphicNum++; }
*off: C++, . , :
" ". 200 project euler- , C++,Code:n = int(raw_input("N = ")) print filter(lambda x: str(x*x)[-len(str(x)):] == str(x), xrange(1, n))
Last edited by anrieff; 5th November 2014 at 09:00.
, . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
5th November 2014 08:39 #4n 18 - * unsigned long long (64 )Code:
#include <iostream> using namespace std; int main () { unsigned long long a=1, aq, i=0, n, z=10; cout<<"N = "; cin>>n; if (n>18) n=18; while (i<n) { aq = a * a; if (aq%z == a) { i++; cout<<i<<". "<<a<<" "<<aq<<endl;; } a++; if (a>z) z*=10; } system("pause"); return 0; }
[edit] 1 . 10x haterasLast edited by ined; 5th November 2014 at 11:12.
ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173
-
5th November 2014 08:58 #5
. , 1..n, n . , squareAutoNum:
while , .Code:int squareAutoNum = automorphicNum*automorphicNum;
out of curiosity, :
Code:import itertools n = int(raw_input("N = ")) print list(itertools.islice((x for x in itertools.count(1) if str(x*x)[-len(str(x)):] == str(x)), 0, n)), . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
5th November 2014 10:29 #6
/off
@anrieff:
, , ...
- ,
/eoff
@ined: .
, , 5 6.
, .ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1
-
7th November 2014 18:22 #7
, - - - . 4*109 n 18 - 1018 n 33
Code:#include <iostream> #include <iomanip> #define MIL 1000000000ull using namespace std; int i=0, n; void print(unsigned long long a) { i++; cout<<setw(2)<<i<<". "<<setw(3+n/2)<<a<<endl; } unsigned long long ssq(unsigned long long a) { unsigned long long h, l, r, s; l = a % MIL; h = a / MIL; r = l * l; if (h==0) return r; s = ((l * h) % MIL) * MIL; return r+s+s; } int main () { unsigned long long a5=5, s5, z5=10; unsigned long long a6=6, s6, z6=10; cout<<"N = "; cin>>n; if (n>33) n=33; print(1); while (i<n) { if (a5<a6) { if (ssq(a5)%z5 == a5) { print(a5); s5 = z5; z5 *= 10; } a5+=s5; if (a5>z5) z5*=10; } if (i==n) break; if (a5>a6) { if (ssq(a6)%z6 == a6) { print(a6); s6 = z6; z6 *=10; } a6+=s6; if (a6>z6) z6*=10; } } system("pause"); return 0; }Last edited by ined; 7th November 2014 at 18:41.
ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in